diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 1123cab807651..0faad06f904af 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -270,6 +270,13 @@ pub enum ObligationCauseCode<'tcx> { parent_code: Lrc>, }, + FunctionCallObligation { + /// The node of the function call. + call_hir_id: hir::HirId, + /// The obligation introduced by this argument. + parent_code: Lrc>, + }, + /// Error derived when matching traits/impls; see ObligationCause for more details CompareImplConstObligation, diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 40cb9647a3555..a4ae766978500 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -2294,6 +2294,18 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ) }); } + ObligationCauseCode::FunctionCallObligation { ref parent_code, .. } => { + ensure_sufficient_stack(|| { + self.note_obligation_cause_code( + err, + predicate, + param_env, + &parent_code, + obligated_types, + seen_requirements, + ) + }); + } ObligationCauseCode::FunctionArgumentObligation { arg_hir_id, call_hir_id, diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index d05dd517f1ea3..b888bbc1a8e7f 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -1137,6 +1137,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } else if error.obligation.cause.span == call_sp { // Make function calls point at the callee, not the whole thing. if let hir::ExprKind::Call(callee, _) = expr.kind { + let parent_code = error.obligation.cause.clone_code(); + *error.obligation.cause.make_mut_code() = + ObligationCauseCode::FunctionCallObligation { + call_hir_id: expr.hir_id, + parent_code, + }; error.obligation.cause.span = callee.span; } }