From 17c6efa9788cf9396750c4edacd4e724e8a7bb2b Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 24 Nov 2024 01:44:16 +0000 Subject: [PATCH 1/3] Disentangle hir node match logic in adjust_fulfillment_errors --- .../src/fn_ctxt/adjust_fulfillment_errors.rs | 111 ++++++++++-------- 1 file changed, 65 insertions(+), 46 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs index b09d78614c321..eb564f96bc029 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs @@ -94,71 +94,82 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.find_ambiguous_parameter_in(def_id, error.root_obligation.predicate); } - let (expr, qpath) = match self.tcx.hir_node(hir_id) { - hir::Node::Expr(expr) => { - if self.closure_span_overlaps_error(error, expr.span) { + match self.tcx.hir_node(hir_id) { + hir::Node::Expr(&hir::Expr { kind: hir::ExprKind::Path(qpath), span, .. }) => { + if self.closure_span_overlaps_error(error, span) { return false; } - let qpath = - if let hir::ExprKind::Path(qpath) = expr.kind { Some(qpath) } else { None }; - (Some(&expr.kind), qpath) - } - hir::Node::Ty(hir::Ty { kind: hir::TyKind::Path(qpath), .. }) => (None, Some(*qpath)), - _ => return false, - }; + if let Some(param) = predicate_self_type_to_point_at + && self.point_at_path_if_possible(error, def_id, param, &qpath) + { + return true; + } - if let Some(qpath) = qpath { - // Prefer pointing at the turbofished arg that corresponds to the - // self type of the failing predicate over anything else. - if let Some(param) = predicate_self_type_to_point_at - && self.point_at_path_if_possible(error, def_id, param, &qpath) - { - return true; - } + if let hir::Node::Expr(hir::Expr { + kind: hir::ExprKind::Call(callee, args), + hir_id: call_hir_id, + span: call_span, + .. + }) = self.tcx.parent_hir_node(hir_id) + && callee.hir_id == hir_id + { + if self.closure_span_overlaps_error(error, *call_span) { + return false; + } - if let hir::Node::Expr(hir::Expr { - kind: hir::ExprKind::Call(callee, args), - hir_id: call_hir_id, - span: call_span, - .. - }) = self.tcx.parent_hir_node(hir_id) - && callee.hir_id == hir_id - { - if self.closure_span_overlaps_error(error, *call_span) { - return false; + for param in + [param_to_point_at, fallback_param_to_point_at, self_param_to_point_at] + .into_iter() + .flatten() + { + if self.blame_specific_arg_if_possible( + error, + def_id, + param, + *call_hir_id, + callee.span, + None, + args, + ) { + return true; + } + } } for param in [param_to_point_at, fallback_param_to_point_at, self_param_to_point_at] .into_iter() .flatten() { - if self.blame_specific_arg_if_possible( - error, - def_id, - param, - *call_hir_id, - callee.span, - None, - args, - ) { + if self.point_at_path_if_possible(error, def_id, param, &qpath) { return true; } } } - - for param in [param_to_point_at, fallback_param_to_point_at, self_param_to_point_at] + hir::Node::Ty(hir::Ty { kind: hir::TyKind::Path(qpath), .. }) => { + for param in [ + predicate_self_type_to_point_at, + param_to_point_at, + fallback_param_to_point_at, + self_param_to_point_at, + ] .into_iter() .flatten() - { - if self.point_at_path_if_possible(error, def_id, param, &qpath) { - return true; + { + if self.point_at_path_if_possible(error, def_id, param, &qpath) { + return true; + } } } - } + hir::Node::Expr(&hir::Expr { + kind: hir::ExprKind::MethodCall(segment, receiver, args, ..), + span, + .. + }) => { + if self.closure_span_overlaps_error(error, span) { + return false; + } - match expr { - Some(hir::ExprKind::MethodCall(segment, receiver, args, ..)) => { if let Some(param) = predicate_self_type_to_point_at && self.point_at_generic_if_possible(error, def_id, param, segment) { @@ -208,7 +219,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return true; } } - Some(hir::ExprKind::Struct(qpath, fields, ..)) => { + hir::Node::Expr(&hir::Expr { + kind: hir::ExprKind::Struct(qpath, fields, ..), + span, + .. + }) => { + if self.closure_span_overlaps_error(error, span) { + return false; + } + if let Res::Def(DefKind::Struct | DefKind::Variant, variant_def_id) = self.typeck_results.borrow().qpath_res(qpath, hir_id) { From 30afeb0357006bf87c8f41f067896e3c0abe11dd Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 24 Nov 2024 01:15:04 +0000 Subject: [PATCH 2/3] Adjust HostEffect error spans correctly to point at args --- compiler/rustc_hir_typeck/src/callee.rs | 19 +++- .../rustc_hir_typeck/src/fn_ctxt/_impl.rs | 3 +- .../src/fn_ctxt/adjust_fulfillment_errors.rs | 107 +++++++++++++++--- compiler/rustc_hir_typeck/src/place_op.rs | 2 +- compiler/rustc_middle/src/traits/mod.rs | 4 + .../src/error_reporting/traits/suggestions.rs | 5 +- .../ui/consts/const-block-const-bound.stderr | 12 +- ...constifconst-call-in-const-position.stderr | 4 +- tests/ui/consts/fn_trait_refs.stderr | 75 ++++++++++-- .../impl-trait/normalize-tait-in-const.stderr | 12 +- ...assoc-type-const-bound-usage-fail-2.stderr | 4 +- .../assoc-type-const-bound-usage-fail.stderr | 4 +- .../const-traits/call-const-closure.stderr | 4 +- .../call-const-in-tilde-const.stderr | 2 +- .../call-const-trait-method-fail.stderr | 2 +- .../call-generic-method-nonconst.stderr | 12 +- .../const-default-method-bodies.stderr | 4 +- .../const-traits/const-drop-bound.stderr | 12 +- .../const-drop-fail-2.precise.stderr | 16 +-- .../const-drop-fail-2.stock.stderr | 16 +-- .../const-drop-fail.precise.stderr | 39 +++---- .../ui/traits/const-traits/const-drop-fail.rs | 4 +- .../const-traits/const-drop-fail.stock.stderr | 39 +++---- .../const-traits/const-opaque.no.stderr | 16 ++- .../const-traits/cross-crate.gatednc.stderr | 4 +- ...-method-body-is-const-body-checking.stderr | 10 +- ...-method-body-is-const-same-trait-ck.stderr | 4 +- .../effects/minicore-fn-fail.stderr | 12 +- .../effects/no-explicit-const-params.stderr | 4 +- .../specializing-constness-2.stderr | 4 +- .../super-traits-fail-2.yn.stderr | 4 +- .../super-traits-fail-2.yy.stderr | 4 +- .../super-traits-fail-3.yn.stderr | 4 +- .../tilde-const-and-const-params.stderr | 4 +- .../trait-where-clause-const.stderr | 18 ++- .../unsatisfied-const-trait-bound.stderr | 8 +- 36 files changed, 361 insertions(+), 136 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index a92482e6a0e39..b0afbab8e01b8 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -4,7 +4,7 @@ use rustc_ast::util::parser::PREC_UNAMBIGUOUS; use rustc_errors::{Applicability, Diag, ErrorGuaranteed, StashKey}; use rustc_hir::def::{self, CtorKind, Namespace, Res}; use rustc_hir::def_id::DefId; -use rustc_hir::{self as hir, LangItem}; +use rustc_hir::{self as hir, HirId, LangItem}; use rustc_hir_analysis::autoderef::Autoderef; use rustc_infer::infer; use rustc_infer::traits::{self, Obligation, ObligationCause, ObligationCauseCode}; @@ -428,7 +428,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> Ty<'tcx> { let (fn_sig, def_id) = match *callee_ty.kind() { ty::FnDef(def_id, args) => { - self.enforce_context_effects(call_expr.span, def_id, args); + self.enforce_context_effects(Some(call_expr.hir_id), call_expr.span, def_id, args); let fn_sig = self.tcx.fn_sig(def_id).instantiate(self.tcx, args); // Unit testing: function items annotated with @@ -837,6 +837,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { #[tracing::instrument(level = "debug", skip(self, span))] pub(super) fn enforce_context_effects( &self, + call_hir_id: Option, span: Span, callee_did: DefId, callee_args: GenericArgsRef<'tcx>, @@ -867,10 +868,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if self.tcx.is_conditionally_const(callee_did) { let q = self.tcx.const_conditions(callee_did); // FIXME(const_trait_impl): Use this span with a better cause code. - for (cond, _) in q.instantiate(self.tcx, callee_args) { + for (idx, (cond, pred_span)) in + q.instantiate(self.tcx, callee_args).into_iter().enumerate() + { + let cause = self.cause( + span, + if let Some(hir_id) = call_hir_id { + ObligationCauseCode::HostEffectInExpr(callee_did, pred_span, hir_id, idx) + } else { + ObligationCauseCode::WhereClause(callee_did, pred_span) + }, + ); self.register_predicate(Obligation::new( self.tcx, - self.misc(span), + cause, self.param_env, cond.to_host_effect_clause(self.tcx, host), )); diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 47af8c681da00..76bbcfd1312db 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -185,7 +185,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { span: Span, method: MethodCallee<'tcx>, ) { - self.enforce_context_effects(span, method.def_id, method.args); + self.enforce_context_effects(Some(hir_id), span, method.def_id, method.args); self.write_resolution(hir_id, Ok((DefKind::AssocFn, method.def_id))); self.write_args(hir_id, method.args); } @@ -263,6 +263,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } Adjust::Deref(Some(overloaded_deref)) => { self.enforce_context_effects( + None, expr.span, overloaded_deref.method_call(self.tcx), self.tcx.mk_args(&[a.target.into()]), diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs index eb564f96bc029..3dd82249d3308 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs @@ -11,26 +11,56 @@ use rustc_trait_selection::traits; use crate::FnCtxt; +enum ClauseFlavor { + /// Predicate comes from `predicates_of`. + Where, + /// Predicate comes from `const_conditions`. + Const, +} + impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(crate) fn adjust_fulfillment_error_for_expr_obligation( &self, error: &mut traits::FulfillmentError<'tcx>, ) -> bool { - let ObligationCauseCode::WhereClauseInExpr(def_id, _, hir_id, idx) = - *error.obligation.cause.code().peel_derives() - else { - return false; + let (def_id, hir_id, idx, flavor) = match *error.obligation.cause.code().peel_derives() { + ObligationCauseCode::WhereClauseInExpr(def_id, _, hir_id, idx) => { + (def_id, hir_id, idx, ClauseFlavor::Where) + } + ObligationCauseCode::HostEffectInExpr(def_id, _, hir_id, idx) => { + (def_id, hir_id, idx, ClauseFlavor::Const) + } + _ => return false, }; - let Some(uninstantiated_pred) = self - .tcx - .predicates_of(def_id) - .instantiate_identity(self.tcx) - .predicates - .into_iter() - .nth(idx) - else { - return false; + let uninstantiated_pred = match flavor { + ClauseFlavor::Where => { + if let Some(pred) = self + .tcx + .predicates_of(def_id) + .instantiate_identity(self.tcx) + .predicates + .into_iter() + .nth(idx) + { + pred + } else { + return false; + } + } + ClauseFlavor::Const => { + if let Some((pred, _)) = self + .tcx + .const_conditions(def_id) + .instantiate_identity(self.tcx) + .into_iter() + .nth(idx) + { + pred.to_host_effect_clause(self.tcx, ty::BoundConstness::Maybe) + } else { + return false; + } + } }; let generics = self.tcx.generics_of(def_id); @@ -39,6 +69,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::ClauseKind::Trait(pred) => { (pred.trait_ref.args.to_vec(), Some(pred.self_ty().into())) } + ty::ClauseKind::HostEffect(pred) => { + (pred.trait_ref.args.to_vec(), Some(pred.self_ty().into())) + } ty::ClauseKind::Projection(pred) => (pred.projection_term.args.to_vec(), None), ty::ClauseKind::ConstArgHasType(arg, ty) => (vec![ty.into(), arg.into()], None), ty::ClauseKind::ConstEvaluatable(e) => (vec![e.into()], None), @@ -95,6 +128,51 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } match self.tcx.hir_node(hir_id) { + hir::Node::Expr(&hir::Expr { + kind: + hir::ExprKind::Call( + hir::Expr { kind: hir::ExprKind::Path(qpath), span: callee_span, .. }, + args, + ), + span, + .. + }) => { + if self.closure_span_overlaps_error(error, span) { + return false; + } + + if let Some(param) = predicate_self_type_to_point_at + && self.point_at_path_if_possible(error, def_id, param, &qpath) + { + return true; + } + + for param in [param_to_point_at, fallback_param_to_point_at, self_param_to_point_at] + .into_iter() + .flatten() + { + if self.blame_specific_arg_if_possible( + error, + def_id, + param, + hir_id, + *callee_span, + None, + args, + ) { + return true; + } + } + + for param in [param_to_point_at, fallback_param_to_point_at, self_param_to_point_at] + .into_iter() + .flatten() + { + if self.point_at_path_if_possible(error, def_id, param, &qpath) { + return true; + } + } + } hir::Node::Expr(&hir::Expr { kind: hir::ExprKind::Path(qpath), span, .. }) => { if self.closure_span_overlaps_error(error, span) { return false; @@ -544,7 +622,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expr: &'tcx hir::Expr<'tcx>, ) -> Result<&'tcx hir::Expr<'tcx>, &'tcx hir::Expr<'tcx>> { match obligation_cause_code { - traits::ObligationCauseCode::WhereClauseInExpr(_, _, _, _) => { + traits::ObligationCauseCode::WhereClauseInExpr(_, _, _, _) + | ObligationCauseCode::HostEffectInExpr(..) => { // This is the "root"; we assume that the `expr` is already pointing here. // Therefore, we return `Ok` so that this `expr` can be refined further. Ok(expr) diff --git a/compiler/rustc_hir_typeck/src/place_op.rs b/compiler/rustc_hir_typeck/src/place_op.rs index 3d401cef76f7d..7c667511aa997 100644 --- a/compiler/rustc_hir_typeck/src/place_op.rs +++ b/compiler/rustc_hir_typeck/src/place_op.rs @@ -296,7 +296,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); }; *deref = OverloadedDeref { mutbl, span: deref.span }; - self.enforce_context_effects(expr.span, method.def_id, method.args); + self.enforce_context_effects(None, expr.span, method.def_id, method.args); // If this is a union field, also throw an error for `DerefMut` of `ManuallyDrop` (see RFC 2514). // This helps avoid accidental drops. if inside_union diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index d61ef7641ee9f..0a77c3bc42fb9 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -204,6 +204,10 @@ pub enum ObligationCauseCode<'tcx> { /// list of the item. WhereClauseInExpr(DefId, Span, HirId, usize), + /// Like `WhereClauseinExpr`, but indexes into the `const_conditions` + /// rather than the `predicates_of`. + HostEffectInExpr(DefId, Span, HirId, usize), + /// A type like `&'a T` is WF only if `T: 'a`. ReferenceOutlivesReferent(Ty<'tcx>), diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 27b45f7094645..2bb503f17b4ed 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -2803,6 +2803,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } ObligationCauseCode::WhereClause(item_def_id, span) | ObligationCauseCode::WhereClauseInExpr(item_def_id, span, ..) + | ObligationCauseCode::HostEffectInExpr(item_def_id, span, ..) if !span.is_dummy() => { if let ObligationCauseCode::WhereClauseInExpr(_, _, hir_id, pos) = &cause_code { @@ -2966,7 +2967,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { err.help(help); } } - ObligationCauseCode::WhereClause(..) | ObligationCauseCode::WhereClauseInExpr(..) => { + ObligationCauseCode::WhereClause(..) + | ObligationCauseCode::WhereClauseInExpr(..) + | ObligationCauseCode::HostEffectInExpr(..) => { // We hold the `DefId` of the item introducing the obligation, but displaying it // doesn't add user usable information. It always point at an associated item. } diff --git a/tests/ui/consts/const-block-const-bound.stderr b/tests/ui/consts/const-block-const-bound.stderr index b2b2f62c58f27..0931eff2175bc 100644 --- a/tests/ui/consts/const-block-const-bound.stderr +++ b/tests/ui/consts/const-block-const-bound.stderr @@ -1,8 +1,16 @@ error[E0277]: the trait bound `UnconstDrop: const Destruct` is not satisfied - --> $DIR/const-block-const-bound.rs:18:9 + --> $DIR/const-block-const-bound.rs:18:11 | LL | f(UnconstDrop); - | ^^^^^^^^^^^^^^ + | - ^^^^^^^^^^^ + | | + | required by a bound introduced by this call + | +note: required by a bound in `f` + --> $DIR/const-block-const-bound.rs:8:15 + | +LL | const fn f(x: T) {} + | ^^^^^^ required by this bound in `f` error: aborting due to 1 previous error diff --git a/tests/ui/consts/constifconst-call-in-const-position.stderr b/tests/ui/consts/constifconst-call-in-const-position.stderr index 6add83dc52c57..c778299560fab 100644 --- a/tests/ui/consts/constifconst-call-in-const-position.stderr +++ b/tests/ui/consts/constifconst-call-in-const-position.stderr @@ -2,13 +2,13 @@ error[E0277]: the trait bound `T: const Tr` is not satisfied --> $DIR/constifconst-call-in-const-position.rs:17:38 | LL | const fn foo() -> [u8; T::a()] { - | ^^^^^^ + | ^ error[E0277]: the trait bound `T: const Tr` is not satisfied --> $DIR/constifconst-call-in-const-position.rs:18:9 | LL | [0; T::a()] - | ^^^^^^ + | ^ error: aborting due to 2 previous errors diff --git a/tests/ui/consts/fn_trait_refs.stderr b/tests/ui/consts/fn_trait_refs.stderr index 108500217139e..11e13c3efdd19 100644 --- a/tests/ui/consts/fn_trait_refs.stderr +++ b/tests/ui/consts/fn_trait_refs.stderr @@ -121,34 +121,89 @@ LL | T: ~const FnMut<()> + ~const Destruct, = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0277]: the trait bound `fn() -> i32 {one}: const Destruct` is not satisfied - --> $DIR/fn_trait_refs.rs:70:24 + --> $DIR/fn_trait_refs.rs:70:32 | LL | let test_one = test_fn(one); - | ^^^^^^^^^^^^ + | ------- ^^^ + | | + | required by a bound introduced by this call + | +note: required by a bound in `test_fn` + --> $DIR/fn_trait_refs.rs:35:24 + | +LL | const fn test_fn(mut f: T) -> (T::Output, T::Output, T::Output) + | ------- required by a bound in this function +LL | where +LL | T: ~const Fn<()> + ~const Destruct, + | ^^^^^^ required by this bound in `test_fn` error[E0277]: the trait bound `fn() -> i32 {two}: const Destruct` is not satisfied - --> $DIR/fn_trait_refs.rs:73:24 + --> $DIR/fn_trait_refs.rs:73:36 | LL | let test_two = test_fn_mut(two); - | ^^^^^^^^^^^^^^^^ + | ----------- ^^^ + | | + | required by a bound introduced by this call + | +note: required by a bound in `test_fn_mut` + --> $DIR/fn_trait_refs.rs:49:27 + | +LL | const fn test_fn_mut(mut f: T) -> (T::Output, T::Output) + | ----------- required by a bound in this function +LL | where +LL | T: ~const FnMut<()> + ~const Destruct, + | ^^^^^^ required by this bound in `test_fn_mut` error[E0277]: the trait bound `&T: ~const Destruct` is not satisfied - --> $DIR/fn_trait_refs.rs:39:9 + --> $DIR/fn_trait_refs.rs:39:19 | LL | tester_fn(&f), - | ^^^^^^^^^^^^^ + | --------- ^^ + | | + | required by a bound introduced by this call + | +note: required by a bound in `tester_fn` + --> $DIR/fn_trait_refs.rs:14:24 + | +LL | const fn tester_fn(f: T) -> T::Output + | --------- required by a bound in this function +LL | where +LL | T: ~const Fn<()> + ~const Destruct, + | ^^^^^^ required by this bound in `tester_fn` error[E0277]: the trait bound `&T: ~const Destruct` is not satisfied - --> $DIR/fn_trait_refs.rs:41:9 + --> $DIR/fn_trait_refs.rs:41:23 | LL | tester_fn_mut(&f), - | ^^^^^^^^^^^^^^^^^ + | ------------- ^^ + | | + | required by a bound introduced by this call + | +note: required by a bound in `tester_fn_mut` + --> $DIR/fn_trait_refs.rs:21:27 + | +LL | const fn tester_fn_mut(mut f: T) -> T::Output + | ------------- required by a bound in this function +LL | where +LL | T: ~const FnMut<()> + ~const Destruct, + | ^^^^^^ required by this bound in `tester_fn_mut` error[E0277]: the trait bound `&mut T: ~const Destruct` is not satisfied - --> $DIR/fn_trait_refs.rs:53:9 + --> $DIR/fn_trait_refs.rs:53:23 | LL | tester_fn_mut(&mut f), - | ^^^^^^^^^^^^^^^^^^^^^ + | ------------- ^^^^^^ + | | + | required by a bound introduced by this call + | +note: required by a bound in `tester_fn_mut` + --> $DIR/fn_trait_refs.rs:21:27 + | +LL | const fn tester_fn_mut(mut f: T) -> T::Output + | ------------- required by a bound in this function +LL | where +LL | T: ~const FnMut<()> + ~const Destruct, + | ^^^^^^ required by this bound in `tester_fn_mut` error[E0015]: cannot call non-const closure in constant functions --> $DIR/fn_trait_refs.rs:16:5 diff --git a/tests/ui/impl-trait/normalize-tait-in-const.stderr b/tests/ui/impl-trait/normalize-tait-in-const.stderr index bb874cbe41b33..203fbfc1d2c55 100644 --- a/tests/ui/impl-trait/normalize-tait-in-const.stderr +++ b/tests/ui/impl-trait/normalize-tait-in-const.stderr @@ -13,10 +13,18 @@ LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruc = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0277]: the trait bound `for<'a, 'b> fn(&'a foo::Alias<'b>) {foo}: const Destruct` is not satisfied - --> $DIR/normalize-tait-in-const.rs:33:5 + --> $DIR/normalize-tait-in-const.rs:33:19 | LL | with_positive(foo); - | ^^^^^^^^^^^^^^^^^^ + | ------------- ^^^ + | | + | required by a bound introduced by this call + | +note: required by a bound in `with_positive` + --> $DIR/normalize-tait-in-const.rs:26:62 + | +LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { + | ^^^^^^ required by this bound in `with_positive` error[E0015]: cannot call non-const closure in constant functions --> $DIR/normalize-tait-in-const.rs:27:5 diff --git a/tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail-2.stderr b/tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail-2.stderr index 86bd07a5f593d..c7af0a220ca31 100644 --- a/tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail-2.stderr +++ b/tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail-2.stderr @@ -2,13 +2,13 @@ error[E0277]: the trait bound `::Assoc: ~const Trait` is not sati --> $DIR/assoc-type-const-bound-usage-fail-2.rs:23:5 | LL | T::Assoc::::func(); - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ error[E0277]: the trait bound `::Assoc: ~const Trait` is not satisfied --> $DIR/assoc-type-const-bound-usage-fail-2.rs:25:5 | LL | ::Assoc::::func(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail.stderr b/tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail.stderr index 145fe2c41dd40..99fc924ad06b9 100644 --- a/tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail.stderr +++ b/tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail.stderr @@ -2,13 +2,13 @@ error[E0277]: the trait bound `T: ~const Trait` is not satisfied --> $DIR/assoc-type-const-bound-usage-fail.rs:16:5 | LL | T::Assoc::func(); - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^ error[E0277]: the trait bound `T: ~const Trait` is not satisfied --> $DIR/assoc-type-const-bound-usage-fail.rs:18:5 | LL | ::Assoc::func(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/traits/const-traits/call-const-closure.stderr b/tests/ui/traits/const-traits/call-const-closure.stderr index 3fed67f5d0884..fe7c115aaab44 100644 --- a/tests/ui/traits/const-traits/call-const-closure.stderr +++ b/tests/ui/traits/const-traits/call-const-closure.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `(): ~const Bar` is not satisfied - --> $DIR/call-const-closure.rs:17:15 + --> $DIR/call-const-closure.rs:17:18 | LL | (const || ().foo())(); - | ^^^^^^^^ + | ^^^ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/call-const-in-tilde-const.stderr b/tests/ui/traits/const-traits/call-const-in-tilde-const.stderr index e56968b90972d..b9dabceb5de47 100644 --- a/tests/ui/traits/const-traits/call-const-in-tilde-const.stderr +++ b/tests/ui/traits/const-traits/call-const-in-tilde-const.stderr @@ -2,7 +2,7 @@ error[E0277]: the trait bound `T: const Foo` is not satisfied --> $DIR/call-const-in-tilde-const.rs:9:13 | LL | const { T::foo() } - | ^^^^^^^^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/call-const-trait-method-fail.stderr b/tests/ui/traits/const-traits/call-const-trait-method-fail.stderr index b461fd9e39e3c..64850335c2ab6 100644 --- a/tests/ui/traits/const-traits/call-const-trait-method-fail.stderr +++ b/tests/ui/traits/const-traits/call-const-trait-method-fail.stderr @@ -2,7 +2,7 @@ error[E0277]: the trait bound `u32: ~const Plus` is not satisfied --> $DIR/call-const-trait-method-fail.rs:26:5 | LL | a.plus(b) - | ^^^^^^^^^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/call-generic-method-nonconst.stderr b/tests/ui/traits/const-traits/call-generic-method-nonconst.stderr index d881bd5f4de61..74a22186a1637 100644 --- a/tests/ui/traits/const-traits/call-generic-method-nonconst.stderr +++ b/tests/ui/traits/const-traits/call-generic-method-nonconst.stderr @@ -1,8 +1,16 @@ error[E0277]: the trait bound `S: const Foo` is not satisfied - --> $DIR/call-generic-method-nonconst.rs:24:22 + --> $DIR/call-generic-method-nonconst.rs:24:34 | LL | pub const EQ: bool = equals_self(&S); - | ^^^^^^^^^^^^^^^ + | ----------- ^^ + | | + | required by a bound introduced by this call + | +note: required by a bound in `equals_self` + --> $DIR/call-generic-method-nonconst.rs:17:25 + | +LL | const fn equals_self(t: &T) -> bool { + | ^^^^^^ required by this bound in `equals_self` error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/const-default-method-bodies.stderr b/tests/ui/traits/const-traits/const-default-method-bodies.stderr index 5879330f15823..903f7d37f9d8e 100644 --- a/tests/ui/traits/const-traits/const-default-method-bodies.stderr +++ b/tests/ui/traits/const-traits/const-default-method-bodies.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `NonConstImpl: ~const ConstDefaultFn` is not satisfied - --> $DIR/const-default-method-bodies.rs:25:5 + --> $DIR/const-default-method-bodies.rs:25:18 | LL | NonConstImpl.a(); - | ^^^^^^^^^^^^^^^^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/const-drop-bound.stderr b/tests/ui/traits/const-traits/const-drop-bound.stderr index 60718cc84c101..78ba0279566de 100644 --- a/tests/ui/traits/const-traits/const-drop-bound.stderr +++ b/tests/ui/traits/const-traits/const-drop-bound.stderr @@ -1,8 +1,16 @@ error[E0277]: the trait bound `Foo: ~const Destruct` is not satisfied - --> $DIR/const-drop-bound.rs:23:5 + --> $DIR/const-drop-bound.rs:23:9 | LL | foo(res) - | ^^^^^^^^ + | --- ^^^ + | | + | required by a bound introduced by this call + | +note: required by a bound in `foo` + --> $DIR/const-drop-bound.rs:9:61 + | +LL | const fn foo(res: Result) -> Option where E: ~const Destruct { + | ^^^^^^ required by this bound in `foo` error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/const-drop-fail-2.precise.stderr b/tests/ui/traits/const-traits/const-drop-fail-2.precise.stderr index bb9966c7ec393..7b2cafb612441 100644 --- a/tests/ui/traits/const-traits/const-drop-fail-2.precise.stderr +++ b/tests/ui/traits/const-traits/const-drop-fail-2.precise.stderr @@ -1,12 +1,14 @@ error[E0277]: the trait bound `ConstDropImplWithBounds: const Destruct` is not satisfied - --> $DIR/const-drop-fail-2.rs:31:15 + --> $DIR/const-drop-fail-2.rs:31:23 | -LL | const _: () = check::>( - | _______________^ -LL | | -LL | | ConstDropImplWithBounds(PhantomData) -LL | | ); - | |_^ +LL | const _: () = check::>( + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: required by a bound in `check` + --> $DIR/const-drop-fail-2.rs:21:19 + | +LL | const fn check(_: T) {} + | ^^^^^^ required by this bound in `check` error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/const-drop-fail-2.stock.stderr b/tests/ui/traits/const-traits/const-drop-fail-2.stock.stderr index bb9966c7ec393..7b2cafb612441 100644 --- a/tests/ui/traits/const-traits/const-drop-fail-2.stock.stderr +++ b/tests/ui/traits/const-traits/const-drop-fail-2.stock.stderr @@ -1,12 +1,14 @@ error[E0277]: the trait bound `ConstDropImplWithBounds: const Destruct` is not satisfied - --> $DIR/const-drop-fail-2.rs:31:15 + --> $DIR/const-drop-fail-2.rs:31:23 | -LL | const _: () = check::>( - | _______________^ -LL | | -LL | | ConstDropImplWithBounds(PhantomData) -LL | | ); - | |_^ +LL | const _: () = check::>( + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: required by a bound in `check` + --> $DIR/const-drop-fail-2.rs:21:19 + | +LL | const fn check(_: T) {} + | ^^^^^^ required by this bound in `check` error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/const-drop-fail.precise.stderr b/tests/ui/traits/const-traits/const-drop-fail.precise.stderr index 67e774fbd0597..8b3e777a0b098 100644 --- a/tests/ui/traits/const-traits/const-drop-fail.precise.stderr +++ b/tests/ui/traits/const-traits/const-drop-fail.precise.stderr @@ -1,31 +1,32 @@ error[E0277]: the trait bound `NonTrivialDrop: const Destruct` is not satisfied - --> $DIR/const-drop-fail.rs:27:23 + --> $DIR/const-drop-fail.rs:32:5 | -LL | const _: () = check($exp); - | ^^^^^^^^^^^ +LL | const _: () = check($exp); + | ----- required by a bound introduced by this call ... -LL | / check_all! { -LL | | NonTrivialDrop, -LL | | ConstImplWithDropGlue(NonTrivialDrop), -LL | | } - | |_- in this macro invocation +LL | NonTrivialDrop, + | ^^^^^^^^^^^^^^ | - = note: this error originates in the macro `check_all` (in Nightly builds, run with -Z macro-backtrace for more info) +note: required by a bound in `check` + --> $DIR/const-drop-fail.rs:23:19 + | +LL | const fn check(_: T) {} + | ^^^^^^ required by this bound in `check` error[E0277]: the trait bound `NonTrivialDrop: const Destruct` is not satisfied - --> $DIR/const-drop-fail.rs:27:23 + --> $DIR/const-drop-fail.rs:34:5 | -LL | const _: () = check($exp); - | ^^^^^^^^^^^ +LL | const _: () = check($exp); + | ----- required by a bound introduced by this call ... -LL | / check_all! { -LL | | NonTrivialDrop, -LL | | ConstImplWithDropGlue(NonTrivialDrop), -LL | | } - | |_- in this macro invocation +LL | ConstImplWithDropGlue(NonTrivialDrop), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: required by a bound in `check` + --> $DIR/const-drop-fail.rs:23:19 | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - = note: this error originates in the macro `check_all` (in Nightly builds, run with -Z macro-backtrace for more info) +LL | const fn check(_: T) {} + | ^^^^^^ required by this bound in `check` error: aborting due to 2 previous errors diff --git a/tests/ui/traits/const-traits/const-drop-fail.rs b/tests/ui/traits/const-traits/const-drop-fail.rs index 08435266e1f80..5e05b9db474a6 100644 --- a/tests/ui/traits/const-traits/const-drop-fail.rs +++ b/tests/ui/traits/const-traits/const-drop-fail.rs @@ -25,14 +25,14 @@ const fn check(_: T) {} macro_rules! check_all { ($($exp:expr),*$(,)?) => {$( const _: () = check($exp); - //~^ ERROR the trait bound `NonTrivialDrop: const Destruct` is not satisfied - //~| ERROR the trait bound `NonTrivialDrop: const Destruct` is not satisfied )*}; } check_all! { NonTrivialDrop, + //~^ ERROR the trait bound `NonTrivialDrop: const Destruct` is not satisfied ConstImplWithDropGlue(NonTrivialDrop), + //~^ ERROR the trait bound `NonTrivialDrop: const Destruct` is not satisfied } fn main() {} diff --git a/tests/ui/traits/const-traits/const-drop-fail.stock.stderr b/tests/ui/traits/const-traits/const-drop-fail.stock.stderr index 67e774fbd0597..8b3e777a0b098 100644 --- a/tests/ui/traits/const-traits/const-drop-fail.stock.stderr +++ b/tests/ui/traits/const-traits/const-drop-fail.stock.stderr @@ -1,31 +1,32 @@ error[E0277]: the trait bound `NonTrivialDrop: const Destruct` is not satisfied - --> $DIR/const-drop-fail.rs:27:23 + --> $DIR/const-drop-fail.rs:32:5 | -LL | const _: () = check($exp); - | ^^^^^^^^^^^ +LL | const _: () = check($exp); + | ----- required by a bound introduced by this call ... -LL | / check_all! { -LL | | NonTrivialDrop, -LL | | ConstImplWithDropGlue(NonTrivialDrop), -LL | | } - | |_- in this macro invocation +LL | NonTrivialDrop, + | ^^^^^^^^^^^^^^ | - = note: this error originates in the macro `check_all` (in Nightly builds, run with -Z macro-backtrace for more info) +note: required by a bound in `check` + --> $DIR/const-drop-fail.rs:23:19 + | +LL | const fn check(_: T) {} + | ^^^^^^ required by this bound in `check` error[E0277]: the trait bound `NonTrivialDrop: const Destruct` is not satisfied - --> $DIR/const-drop-fail.rs:27:23 + --> $DIR/const-drop-fail.rs:34:5 | -LL | const _: () = check($exp); - | ^^^^^^^^^^^ +LL | const _: () = check($exp); + | ----- required by a bound introduced by this call ... -LL | / check_all! { -LL | | NonTrivialDrop, -LL | | ConstImplWithDropGlue(NonTrivialDrop), -LL | | } - | |_- in this macro invocation +LL | ConstImplWithDropGlue(NonTrivialDrop), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: required by a bound in `check` + --> $DIR/const-drop-fail.rs:23:19 | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - = note: this error originates in the macro `check_all` (in Nightly builds, run with -Z macro-backtrace for more info) +LL | const fn check(_: T) {} + | ^^^^^^ required by this bound in `check` error: aborting due to 2 previous errors diff --git a/tests/ui/traits/const-traits/const-opaque.no.stderr b/tests/ui/traits/const-traits/const-opaque.no.stderr index e43a6b603fda1..1278e1257467b 100644 --- a/tests/ui/traits/const-traits/const-opaque.no.stderr +++ b/tests/ui/traits/const-traits/const-opaque.no.stderr @@ -1,14 +1,22 @@ error[E0277]: the trait bound `(): const Foo` is not satisfied - --> $DIR/const-opaque.rs:31:18 + --> $DIR/const-opaque.rs:31:22 | LL | let opaque = bar(()); - | ^^^^^^^ + | --- ^^ + | | + | required by a bound introduced by this call + | +note: required by a bound in `bar` + --> $DIR/const-opaque.rs:26:17 + | +LL | const fn bar(t: T) -> impl ~const Foo { + | ^^^^^^ required by this bound in `bar` error[E0277]: the trait bound `(): const Foo` is not satisfied - --> $DIR/const-opaque.rs:33:5 + --> $DIR/const-opaque.rs:33:12 | LL | opaque.method(); - | ^^^^^^^^^^^^^^^ + | ^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/traits/const-traits/cross-crate.gatednc.stderr b/tests/ui/traits/const-traits/cross-crate.gatednc.stderr index b6f2434140d6a..4d5abf643a8c2 100644 --- a/tests/ui/traits/const-traits/cross-crate.gatednc.stderr +++ b/tests/ui/traits/const-traits/cross-crate.gatednc.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `cross_crate::NonConst: ~const cross_crate::MyTrait` is not satisfied - --> $DIR/cross-crate.rs:19:5 + --> $DIR/cross-crate.rs:19:14 | LL | NonConst.func(); - | ^^^^^^^^^^^^^^^ + | ^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/default-method-body-is-const-body-checking.stderr b/tests/ui/traits/const-traits/default-method-body-is-const-body-checking.stderr index 0534f3eb8d292..8c284bde67e7f 100644 --- a/tests/ui/traits/const-traits/default-method-body-is-const-body-checking.stderr +++ b/tests/ui/traits/const-traits/default-method-body-is-const-body-checking.stderr @@ -1,8 +1,14 @@ error[E0277]: the trait bound `(): ~const Tr` is not satisfied - --> $DIR/default-method-body-is-const-body-checking.rs:12:9 + --> $DIR/default-method-body-is-const-body-checking.rs:12:15 | LL | foo::<()>(); - | ^^^^^^^^^^^ + | ^^ + | +note: required by a bound in `foo` + --> $DIR/default-method-body-is-const-body-checking.rs:7:28 + | +LL | const fn foo() where T: ~const Tr {} + | ^^^^^^ required by this bound in `foo` error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/default-method-body-is-const-same-trait-ck.stderr b/tests/ui/traits/const-traits/default-method-body-is-const-same-trait-ck.stderr index d987cad6f1451..2bd71c940e736 100644 --- a/tests/ui/traits/const-traits/default-method-body-is-const-same-trait-ck.stderr +++ b/tests/ui/traits/const-traits/default-method-body-is-const-same-trait-ck.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `(): ~const Tr` is not satisfied - --> $DIR/default-method-body-is-const-same-trait-ck.rs:9:9 + --> $DIR/default-method-body-is-const-same-trait-ck.rs:9:12 | LL | ().a() - | ^^^^^^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/effects/minicore-fn-fail.stderr b/tests/ui/traits/const-traits/effects/minicore-fn-fail.stderr index cf158643b3472..fa8be631a26bb 100644 --- a/tests/ui/traits/const-traits/effects/minicore-fn-fail.stderr +++ b/tests/ui/traits/const-traits/effects/minicore-fn-fail.stderr @@ -1,8 +1,16 @@ error[E0277]: the trait bound `(): ~const Foo` is not satisfied - --> $DIR/minicore-fn-fail.rs:19:5 + --> $DIR/minicore-fn-fail.rs:19:19 | LL | call_indirect(&foo::<()>); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ------------- ^^^^^^^^^^ + | | + | required by a bound introduced by this call + | +note: required by a bound in `call_indirect` + --> $DIR/minicore-fn-fail.rs:11:27 + | +LL | const fn call_indirect(t: &T) { t() } + | ^^^^^^ required by this bound in `call_indirect` error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/effects/no-explicit-const-params.stderr b/tests/ui/traits/const-traits/effects/no-explicit-const-params.stderr index 0b8e4696c4613..9bd2c2cb8da2a 100644 --- a/tests/ui/traits/const-traits/effects/no-explicit-const-params.stderr +++ b/tests/ui/traits/const-traits/effects/no-explicit-const-params.stderr @@ -27,10 +27,10 @@ LL | trait Bar { | ^^^ error[E0277]: the trait bound `(): const Bar` is not satisfied - --> $DIR/no-explicit-const-params.rs:24:5 + --> $DIR/no-explicit-const-params.rs:24:6 | LL | <() as Bar>::bar(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^ error[E0107]: function takes 0 generic arguments but 1 generic argument was supplied --> $DIR/no-explicit-const-params.rs:15:5 diff --git a/tests/ui/traits/const-traits/specializing-constness-2.stderr b/tests/ui/traits/const-traits/specializing-constness-2.stderr index 4ad5e3157d4f8..edba836aac354 100644 --- a/tests/ui/traits/const-traits/specializing-constness-2.stderr +++ b/tests/ui/traits/const-traits/specializing-constness-2.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `T: ~const A` is not satisfied - --> $DIR/specializing-constness-2.rs:27:5 + --> $DIR/specializing-constness-2.rs:27:6 | LL | ::a(); - | ^^^^^^^^^^^^^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/super-traits-fail-2.yn.stderr b/tests/ui/traits/const-traits/super-traits-fail-2.yn.stderr index 01ae209016a12..ee49810bacec4 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-2.yn.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-2.yn.stderr @@ -11,10 +11,10 @@ LL | trait Bar: ~const Foo {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `T: ~const Foo` is not satisfied - --> $DIR/super-traits-fail-2.rs:20:5 + --> $DIR/super-traits-fail-2.rs:20:7 | LL | x.a(); - | ^^^^^ + | ^ error: aborting due to 2 previous errors diff --git a/tests/ui/traits/const-traits/super-traits-fail-2.yy.stderr b/tests/ui/traits/const-traits/super-traits-fail-2.yy.stderr index ae4c65e4aee1e..a213273c1c78d 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-2.yy.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-2.yy.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `T: ~const Foo` is not satisfied - --> $DIR/super-traits-fail-2.rs:20:5 + --> $DIR/super-traits-fail-2.rs:20:7 | LL | x.a(); - | ^^^^^ + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.yn.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.yn.stderr index 8fcada1bfd1d9..ecee348222d1f 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.yn.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.yn.stderr @@ -25,10 +25,10 @@ LL | const fn foo(x: &T) { = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0277]: the trait bound `T: ~const Foo` is not satisfied - --> $DIR/super-traits-fail-3.rs:24:5 + --> $DIR/super-traits-fail-3.rs:24:7 | LL | x.a(); - | ^^^^^ + | ^ error: aborting due to 4 previous errors diff --git a/tests/ui/traits/const-traits/tilde-const-and-const-params.stderr b/tests/ui/traits/const-traits/tilde-const-and-const-params.stderr index 78bf85e9c6dee..f77d63db054a0 100644 --- a/tests/ui/traits/const-traits/tilde-const-and-const-params.stderr +++ b/tests/ui/traits/const-traits/tilde-const-and-const-params.stderr @@ -26,13 +26,13 @@ error[E0277]: the trait bound `A: const Add42` is not satisfied --> $DIR/tilde-const-and-const-params.rs:27:61 | LL | fn bar(_: Foo) -> Foo<{ A::add(N) }> { - | ^^^^^^^^^ + | ^ error[E0277]: the trait bound `A: const Add42` is not satisfied --> $DIR/tilde-const-and-const-params.rs:9:44 | LL | fn add(self) -> Foo<{ A::add(N) }> { - | ^^^^^^^^^ + | ^ error: aborting due to 4 previous errors diff --git a/tests/ui/traits/const-traits/trait-where-clause-const.stderr b/tests/ui/traits/const-traits/trait-where-clause-const.stderr index d7735ef282f7f..4100ae1c6bfd7 100644 --- a/tests/ui/traits/const-traits/trait-where-clause-const.stderr +++ b/tests/ui/traits/const-traits/trait-where-clause-const.stderr @@ -2,13 +2,25 @@ error[E0277]: the trait bound `T: ~const Bar` is not satisfied --> $DIR/trait-where-clause-const.rs:21:5 | LL | T::b(); - | ^^^^^^ + | ^ + | +note: required by a bound in `Foo::b` + --> $DIR/trait-where-clause-const.rs:15:24 + | +LL | fn b() where Self: ~const Bar; + | ^^^^^^ required by this bound in `Foo::b` error[E0277]: the trait bound `T: ~const Bar` is not satisfied - --> $DIR/trait-where-clause-const.rs:23:5 + --> $DIR/trait-where-clause-const.rs:23:12 | LL | T::c::(); - | ^^^^^^^^^^^ + | ^ + | +note: required by a bound in `Foo::c` + --> $DIR/trait-where-clause-const.rs:16:13 + | +LL | fn c(); + | ^^^^^^ required by this bound in `Foo::c` error: aborting due to 2 previous errors diff --git a/tests/ui/traits/const-traits/unsatisfied-const-trait-bound.stderr b/tests/ui/traits/const-traits/unsatisfied-const-trait-bound.stderr index d04143fc4641d..bda6a029cc2a6 100644 --- a/tests/ui/traits/const-traits/unsatisfied-const-trait-bound.stderr +++ b/tests/ui/traits/const-traits/unsatisfied-const-trait-bound.stderr @@ -10,19 +10,19 @@ error[E0277]: the trait bound `T: const Trait` is not satisfied --> $DIR/unsatisfied-const-trait-bound.rs:29:37 | LL | fn accept0(_: Container<{ T::make() }>) {} - | ^^^^^^^^^ + | ^ error[E0277]: the trait bound `T: const Trait` is not satisfied --> $DIR/unsatisfied-const-trait-bound.rs:33:50 | LL | const fn accept1(_: Container<{ T::make() }>) {} - | ^^^^^^^^^ + | ^ error[E0277]: the trait bound `Ty: const Trait` is not satisfied - --> $DIR/unsatisfied-const-trait-bound.rs:22:5 + --> $DIR/unsatisfied-const-trait-bound.rs:22:15 | LL | require::(); - | ^^^^^^^^^^^^^^^ + | ^^ | note: required by a bound in `require` --> $DIR/unsatisfied-const-trait-bound.rs:8:15 From d5c5d58a37db02f533993187ba1f12f1bde32a54 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 1 Dec 2024 05:11:38 +0000 Subject: [PATCH 3/3] Pull out expr handling --- .../src/fn_ctxt/adjust_fulfillment_errors.rs | 190 +++++++++--------- 1 file changed, 97 insertions(+), 93 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs index 3dd82249d3308..6eaba641888ca 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs @@ -128,21 +128,59 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } match self.tcx.hir_node(hir_id) { - hir::Node::Expr(&hir::Expr { - kind: - hir::ExprKind::Call( - hir::Expr { kind: hir::ExprKind::Path(qpath), span: callee_span, .. }, - args, - ), - span, - .. - }) => { - if self.closure_span_overlaps_error(error, span) { - return false; + hir::Node::Expr(expr) => self.point_at_expr_if_possible( + error, + def_id, + expr, + predicate_self_type_to_point_at, + param_to_point_at, + fallback_param_to_point_at, + self_param_to_point_at, + ), + + hir::Node::Ty(hir::Ty { kind: hir::TyKind::Path(qpath), .. }) => { + for param in [ + predicate_self_type_to_point_at, + param_to_point_at, + fallback_param_to_point_at, + self_param_to_point_at, + ] + .into_iter() + .flatten() + { + if self.point_at_path_if_possible(error, def_id, param, &qpath) { + return true; + } } + false + } + + _ => false, + } + } + + fn point_at_expr_if_possible( + &self, + error: &mut traits::FulfillmentError<'tcx>, + callee_def_id: DefId, + expr: &'tcx hir::Expr<'tcx>, + predicate_self_type_to_point_at: Option>, + param_to_point_at: Option>, + fallback_param_to_point_at: Option>, + self_param_to_point_at: Option>, + ) -> bool { + if self.closure_span_overlaps_error(error, expr.span) { + return false; + } + + match expr.kind { + hir::ExprKind::Call( + hir::Expr { kind: hir::ExprKind::Path(qpath), span: callee_span, .. }, + args, + ) => { if let Some(param) = predicate_self_type_to_point_at - && self.point_at_path_if_possible(error, def_id, param, &qpath) + && self.point_at_path_if_possible(error, callee_def_id, param, &qpath) { return true; } @@ -153,9 +191,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { { if self.blame_specific_arg_if_possible( error, - def_id, + callee_def_id, param, - hir_id, + expr.hir_id, *callee_span, None, args, @@ -168,88 +206,53 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .into_iter() .flatten() { - if self.point_at_path_if_possible(error, def_id, param, &qpath) { + if self.point_at_path_if_possible(error, callee_def_id, param, &qpath) { return true; } } } - hir::Node::Expr(&hir::Expr { kind: hir::ExprKind::Path(qpath), span, .. }) => { - if self.closure_span_overlaps_error(error, span) { - return false; + hir::ExprKind::Path(qpath) => { + // If the parent is an call, then process this as a call. + // + // This is because the `WhereClauseInExpr` obligations come from + // the well-formedness of the *path* expression, but we care to + // point at the call expression (namely, its args). + if let hir::Node::Expr( + call_expr @ hir::Expr { kind: hir::ExprKind::Call(callee, ..), .. }, + ) = self.tcx.parent_hir_node(expr.hir_id) + && callee.hir_id == expr.hir_id + { + return self.point_at_expr_if_possible( + error, + callee_def_id, + call_expr, + predicate_self_type_to_point_at, + param_to_point_at, + fallback_param_to_point_at, + self_param_to_point_at, + ); } + // Otherwise, just try to point at path components. + if let Some(param) = predicate_self_type_to_point_at - && self.point_at_path_if_possible(error, def_id, param, &qpath) + && self.point_at_path_if_possible(error, callee_def_id, param, &qpath) { return true; } - if let hir::Node::Expr(hir::Expr { - kind: hir::ExprKind::Call(callee, args), - hir_id: call_hir_id, - span: call_span, - .. - }) = self.tcx.parent_hir_node(hir_id) - && callee.hir_id == hir_id - { - if self.closure_span_overlaps_error(error, *call_span) { - return false; - } - - for param in - [param_to_point_at, fallback_param_to_point_at, self_param_to_point_at] - .into_iter() - .flatten() - { - if self.blame_specific_arg_if_possible( - error, - def_id, - param, - *call_hir_id, - callee.span, - None, - args, - ) { - return true; - } - } - } - for param in [param_to_point_at, fallback_param_to_point_at, self_param_to_point_at] .into_iter() .flatten() { - if self.point_at_path_if_possible(error, def_id, param, &qpath) { + if self.point_at_path_if_possible(error, callee_def_id, param, &qpath) { return true; } } } - hir::Node::Ty(hir::Ty { kind: hir::TyKind::Path(qpath), .. }) => { - for param in [ - predicate_self_type_to_point_at, - param_to_point_at, - fallback_param_to_point_at, - self_param_to_point_at, - ] - .into_iter() - .flatten() - { - if self.point_at_path_if_possible(error, def_id, param, &qpath) { - return true; - } - } - } - hir::Node::Expr(&hir::Expr { - kind: hir::ExprKind::MethodCall(segment, receiver, args, ..), - span, - .. - }) => { - if self.closure_span_overlaps_error(error, span) { - return false; - } - + hir::ExprKind::MethodCall(segment, receiver, args, ..) => { if let Some(param) = predicate_self_type_to_point_at - && self.point_at_generic_if_possible(error, def_id, param, segment) + && self.point_at_generic_if_possible(error, callee_def_id, param, segment) { // HACK: This is not correct, since `predicate_self_type_to_point_at` might // not actually correspond to the receiver of the method call. But we @@ -259,7 +262,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { error.obligation.cause.map_code(|parent_code| { ObligationCauseCode::FunctionArg { arg_hir_id: receiver.hir_id, - call_hir_id: hir_id, + call_hir_id: expr.hir_id, parent_code, } }); @@ -272,9 +275,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { { if self.blame_specific_arg_if_possible( error, - def_id, + callee_def_id, param, - hir_id, + expr.hir_id, segment.ident.span, Some(receiver), args, @@ -283,7 +286,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } if let Some(param_to_point_at) = param_to_point_at - && self.point_at_generic_if_possible(error, def_id, param_to_point_at, segment) + && self.point_at_generic_if_possible( + error, + callee_def_id, + param_to_point_at, + segment, + ) { return true; } @@ -297,25 +305,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return true; } } - hir::Node::Expr(&hir::Expr { - kind: hir::ExprKind::Struct(qpath, fields, ..), - span, - .. - }) => { - if self.closure_span_overlaps_error(error, span) { - return false; - } - + hir::ExprKind::Struct(qpath, fields, ..) => { if let Res::Def(DefKind::Struct | DefKind::Variant, variant_def_id) = - self.typeck_results.borrow().qpath_res(qpath, hir_id) + self.typeck_results.borrow().qpath_res(qpath, expr.hir_id) { for param in [param_to_point_at, fallback_param_to_point_at, self_param_to_point_at] .into_iter() .flatten() { - let refined_expr = - self.point_at_field_if_possible(def_id, param, variant_def_id, fields); + let refined_expr = self.point_at_field_if_possible( + callee_def_id, + param, + variant_def_id, + fields, + ); match refined_expr { None => {} @@ -339,7 +343,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .into_iter() .flatten() { - if self.point_at_path_if_possible(error, def_id, param, qpath) { + if self.point_at_path_if_possible(error, callee_def_id, param, qpath) { return true; } }