parent
f0c4da4998
commit
a7b4d667fe
8 changed files with 176 additions and 218 deletions
|
@ -10,19 +10,20 @@
|
|||
//!
|
||||
//! This API is completely unstable and subject to change.
|
||||
|
||||
#![allow(rustc::potential_query_instability)]
|
||||
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
||||
#![feature(bool_to_option)]
|
||||
#![feature(box_patterns)]
|
||||
#![feature(drain_filter)]
|
||||
#![feature(control_flow_enum)]
|
||||
#![feature(crate_visibility_modifier)]
|
||||
#![feature(derive_default_enum)]
|
||||
#![feature(drain_filter)]
|
||||
#![feature(hash_drain_filter)]
|
||||
#![feature(label_break_value)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(let_else)]
|
||||
#![feature(never_type)]
|
||||
#![feature(crate_visibility_modifier)]
|
||||
#![feature(control_flow_enum)]
|
||||
#![recursion_limit = "512"] // For rustdoc
|
||||
#![allow(rustc::potential_query_instability)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_macros;
|
||||
|
|
|
@ -1098,8 +1098,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
);
|
||||
}
|
||||
}
|
||||
if let &[ArgKind::Tuple(_, ref fields)] = &expected_args[..] {
|
||||
if fields.len() == found_args.len() && is_closure {
|
||||
if let &[ArgKind::Tuple(_, ref fields)] = &expected_args[..]
|
||||
&& fields.len() == found_args.len()
|
||||
&& is_closure
|
||||
{
|
||||
let sugg = format!(
|
||||
"|({}){}|",
|
||||
found_args
|
||||
|
@ -1135,7 +1137,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err
|
||||
}
|
||||
|
@ -2231,18 +2232,15 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
|
|||
if obligated_types.iter().any(|ot| ot == &self_ty) {
|
||||
return true;
|
||||
}
|
||||
if let ty::Adt(def, substs) = self_ty.kind() {
|
||||
if let [arg] = &substs[..] {
|
||||
if let ty::subst::GenericArgKind::Type(ty) = arg.unpack() {
|
||||
if let ty::Adt(inner_def, _) = ty.kind() {
|
||||
if inner_def == def {
|
||||
if let ty::Adt(def, substs) = self_ty.kind()
|
||||
&& let [arg] = &substs[..]
|
||||
&& let ty::subst::GenericArgKind::Type(ty) = arg.unpack()
|
||||
&& let ty::Adt(inner_def, _) = ty.kind()
|
||||
&& inner_def == def
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -891,10 +891,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
}
|
||||
if let Some(typeck_results) =
|
||||
self.in_progress_typeck_results.map(|t| t.borrow())
|
||||
{
|
||||
let ty = typeck_results.expr_ty_adjusted(base);
|
||||
if let ty::FnDef(def_id, _substs) = ty.kind() {
|
||||
if let Some(hir::Node::Item(hir::Item { span, ident, .. })) =
|
||||
&& let ty = typeck_results.expr_ty_adjusted(base)
|
||||
&& let ty::FnDef(def_id, _substs) = ty.kind()
|
||||
&& let Some(hir::Node::Item(hir::Item { span, ident, .. })) =
|
||||
hir.get_if_local(*def_id)
|
||||
{
|
||||
err.span_suggestion_verbose(
|
||||
|
@ -912,8 +911,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if the trait bound is implemented for a different mutability and note it in the
|
||||
/// final error.
|
||||
|
@ -1000,36 +997,26 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
span: Span,
|
||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||
) {
|
||||
let is_empty_tuple =
|
||||
|ty: ty::Binder<'tcx, Ty<'_>>| *ty.skip_binder().kind() == ty::Tuple(ty::List::empty());
|
||||
|
||||
let hir = self.tcx.hir();
|
||||
let parent_node = hir.get_parent_node(obligation.cause.body_id);
|
||||
let node = hir.find(parent_node);
|
||||
if let Some(hir::Node::Item(hir::Item {
|
||||
kind: hir::ItemKind::Fn(sig, _, body_id), ..
|
||||
})) = node
|
||||
{
|
||||
let body = hir.body(*body_id);
|
||||
if let hir::ExprKind::Block(blk, _) = &body.value.kind {
|
||||
if sig.decl.output.span().overlaps(span)
|
||||
if let Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, _, body_id), .. })) = node
|
||||
&& let body = hir.body(*body_id)
|
||||
&& let hir::ExprKind::Block(blk, _) = &body.value.kind
|
||||
&& sig.decl.output.span().overlaps(span)
|
||||
&& blk.expr.is_none()
|
||||
&& is_empty_tuple(trait_pred.self_ty())
|
||||
{
|
||||
&& *trait_pred.self_ty().skip_binder().kind() == ty::Tuple(ty::List::empty())
|
||||
// FIXME(estebank): When encountering a method with a trait
|
||||
// bound not satisfied in the return type with a body that has
|
||||
// no return, suggest removal of semicolon on last statement.
|
||||
// Once that is added, close #54771.
|
||||
if let Some(ref stmt) = blk.stmts.last() {
|
||||
if let hir::StmtKind::Semi(_) = stmt.kind {
|
||||
&& let Some(stmt) = blk.stmts.last()
|
||||
&& let hir::StmtKind::Semi(_) = stmt.kind
|
||||
{
|
||||
let sp = self.tcx.sess.source_map().end_point(stmt.span);
|
||||
err.span_label(sp, "consider removing this semicolon");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn return_type_span(&self, obligation: &PredicateObligation<'tcx>) -> Option<Span> {
|
||||
let hir = self.tcx.hir();
|
||||
|
@ -2481,9 +2468,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
debug!("suggest_await_before_try: try_trait_obligation {:?}", try_obligation);
|
||||
if self.predicate_may_hold(&try_obligation)
|
||||
&& impls_future.must_apply_modulo_regions()
|
||||
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span)
|
||||
&& snippet.ends_with('?')
|
||||
{
|
||||
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
|
||||
if snippet.ends_with('?') {
|
||||
err.span_suggestion_verbose(
|
||||
span.with_hi(span.hi() - BytePos(1)).shrink_to_hi(),
|
||||
"consider `await`ing on the `Future`",
|
||||
|
@ -2494,8 +2481,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn suggest_floating_point_literal(
|
||||
&self,
|
||||
|
|
|
@ -91,11 +91,9 @@ impl<'tcx> OnUnimplementedDirective {
|
|||
)
|
||||
})?;
|
||||
attr::eval_condition(cond, &tcx.sess.parse_sess, Some(tcx.features()), &mut |item| {
|
||||
if let Some(symbol) = item.value_str() {
|
||||
if parse_value(symbol).is_err() {
|
||||
if let Some(symbol) = item.value_str() && parse_value(symbol).is_err() {
|
||||
errored = true;
|
||||
}
|
||||
}
|
||||
true
|
||||
});
|
||||
Some(cond.clone())
|
||||
|
@ -232,8 +230,7 @@ impl<'tcx> OnUnimplementedDirective {
|
|||
options.iter().filter_map(|(k, v)| v.as_ref().map(|v| (*k, v.to_owned()))).collect();
|
||||
|
||||
for command in self.subcommands.iter().chain(Some(self)).rev() {
|
||||
if let Some(ref condition) = command.condition {
|
||||
if !attr::eval_condition(
|
||||
if let Some(ref condition) = command.condition && !attr::eval_condition(
|
||||
condition,
|
||||
&tcx.sess.parse_sess,
|
||||
Some(tcx.features()),
|
||||
|
@ -250,7 +247,6 @@ impl<'tcx> OnUnimplementedDirective {
|
|||
debug!("evaluate: skipping {:?} due to condition", command);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
debug!("evaluate: {:?} succeeded", command);
|
||||
if let Some(ref message_) = command.message {
|
||||
message = Some(message_.clone());
|
||||
|
|
|
@ -43,9 +43,9 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
|
|||
let c_ty = self.infcx.canonicalize_query(self.param_env.and(ty), &mut orig_values);
|
||||
let span = self.cause.span;
|
||||
debug!("c_ty = {:?}", c_ty);
|
||||
if let Ok(result) = tcx.dropck_outlives(c_ty) {
|
||||
if result.is_proven() {
|
||||
if let Ok(InferOk { value, obligations }) =
|
||||
if let Ok(result) = tcx.dropck_outlives(c_ty)
|
||||
&& result.is_proven()
|
||||
&& let Ok(InferOk { value, obligations }) =
|
||||
self.infcx.instantiate_query_response_and_region_obligations(
|
||||
self.cause,
|
||||
self.param_env,
|
||||
|
@ -57,8 +57,6 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
|
|||
let kinds = value.into_kinds_reporting_overflows(tcx, span, ty);
|
||||
return InferOk { value: kinds, obligations };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Errors and ambiuity in dropck occur in two cases:
|
||||
// - unresolved inference variables at the end of typeck
|
||||
|
|
|
@ -12,23 +12,15 @@ pub(crate) fn update<'tcx, T>(
|
|||
T: TraitEngine<'tcx>,
|
||||
{
|
||||
// (*) binder skipped
|
||||
if let ty::PredicateKind::Trait(predicate) = obligation.predicate.kind().skip_binder() {
|
||||
if let Some(ty) =
|
||||
infcx.shallow_resolve(predicate.self_ty()).ty_vid().map(|t| infcx.root_var(t))
|
||||
{
|
||||
if infcx
|
||||
.tcx
|
||||
.lang_items()
|
||||
.sized_trait()
|
||||
.map_or(false, |st| st != predicate.trait_ref.def_id)
|
||||
if let ty::PredicateKind::Trait(tpred) = obligation.predicate.kind().skip_binder()
|
||||
&& let Some(ty) = infcx.shallow_resolve(tpred.self_ty()).ty_vid().map(|t| infcx.root_var(t))
|
||||
&& infcx.tcx.lang_items().sized_trait().map_or(false, |st| st != tpred.trait_ref.def_id)
|
||||
{
|
||||
let new_self_ty = infcx.tcx.types.unit;
|
||||
|
||||
let trait_ref = ty::TraitRef {
|
||||
substs: infcx
|
||||
.tcx
|
||||
.mk_substs_trait(new_self_ty, &predicate.trait_ref.substs[1..]),
|
||||
..predicate.trait_ref
|
||||
substs: infcx.tcx.mk_substs_trait(new_self_ty, &tpred.trait_ref.substs[1..]),
|
||||
..tpred.trait_ref
|
||||
};
|
||||
|
||||
// Then contstruct a new obligation with Self = () added
|
||||
|
@ -43,21 +35,17 @@ pub(crate) fn update<'tcx, T>(
|
|||
// (*) binder moved here
|
||||
ty::PredicateKind::Trait(ty::TraitPredicate {
|
||||
trait_ref,
|
||||
constness: predicate.constness,
|
||||
polarity: predicate.polarity,
|
||||
constness: tpred.constness,
|
||||
polarity: tpred.polarity,
|
||||
})
|
||||
})
|
||||
.to_predicate(infcx.tcx),
|
||||
);
|
||||
// Don't report overflow errors. Otherwise equivalent to may_hold.
|
||||
if let Ok(result) = infcx.probe(|_| infcx.evaluate_obligation(&o)) {
|
||||
if result.may_apply() {
|
||||
if let Ok(result) = infcx.probe(|_| infcx.evaluate_obligation(&o)) && result.may_apply() {
|
||||
engine.relationships().entry(ty).or_default().self_in_trait = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let ty::PredicateKind::Projection(predicate) = obligation.predicate.kind().skip_binder() {
|
||||
// If the projection predicate (Foo::Bar == X) has X as a non-TyVid,
|
||||
|
|
|
@ -579,9 +579,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
previous_stack,
|
||||
subobligations,
|
||||
);
|
||||
if let Ok(res) = res {
|
||||
if res == EvaluatedToOk || res == EvaluatedToOkModuloRegions {
|
||||
if let Some(key) =
|
||||
if let Ok(eval_rslt) = res
|
||||
&& (eval_rslt == EvaluatedToOk || eval_rslt == EvaluatedToOkModuloRegions)
|
||||
&& let Some(key) =
|
||||
ProjectionCacheKey::from_poly_projection_predicate(
|
||||
self, data,
|
||||
)
|
||||
|
@ -594,9 +594,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
.inner
|
||||
.borrow_mut()
|
||||
.projection_cache()
|
||||
.complete(key, res);
|
||||
}
|
||||
}
|
||||
.complete(key, eval_rslt);
|
||||
}
|
||||
res
|
||||
}
|
||||
|
|
|
@ -224,11 +224,10 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
|
|||
// projection coming from another associated type. See
|
||||
// `src/test/ui/associated-types/point-at-type-on-obligation-failure.rs` and
|
||||
// `traits-assoc-type-in-supertrait-bad.rs`.
|
||||
if let Some(ty::Projection(projection_ty)) = proj.term.ty().map(|ty| ty.kind()) {
|
||||
if let Some(&impl_item_id) =
|
||||
if let Some(ty::Projection(projection_ty)) = proj.term.ty().map(|ty| ty.kind())
|
||||
&& let Some(&impl_item_id) =
|
||||
tcx.impl_item_implementor_ids(impl_def_id).get(&projection_ty.item_def_id)
|
||||
{
|
||||
if let Some(impl_item_span) = items
|
||||
&& let Some(impl_item_span) = items
|
||||
.iter()
|
||||
.find(|item| item.id.def_id.to_def_id() == impl_item_id)
|
||||
.map(fix_span)
|
||||
|
@ -236,17 +235,14 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
|
|||
cause.span = impl_item_span;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ty::PredicateKind::Trait(pred) => {
|
||||
// An associated item obligation born out of the `trait` failed to be met. An example
|
||||
// can be seen in `ui/associated-types/point-at-type-on-obligation-failure-2.rs`.
|
||||
debug!("extended_cause_with_original_assoc_item_obligation trait proj {:?}", pred);
|
||||
if let ty::Projection(ty::ProjectionTy { item_def_id, .. }) = *pred.self_ty().kind() {
|
||||
if let Some(&impl_item_id) =
|
||||
if let ty::Projection(ty::ProjectionTy { item_def_id, .. }) = *pred.self_ty().kind()
|
||||
&& let Some(&impl_item_id) =
|
||||
tcx.impl_item_implementor_ids(impl_def_id).get(&item_def_id)
|
||||
{
|
||||
if let Some(impl_item_span) = items
|
||||
&& let Some(impl_item_span) = items
|
||||
.iter()
|
||||
.find(|item| item.id.def_id.to_def_id() == impl_item_id)
|
||||
.map(fix_span)
|
||||
|
@ -254,8 +250,6 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
|
|||
cause.span = impl_item_span;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue