Skip to content

Commit 3ca2ba0

Browse files
committed
rustc_typeck: add obligation cause code for function call
Fixes rust-lang#90285
1 parent bfb2856 commit 3ca2ba0

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

compiler/rustc_middle/src/traits/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ pub enum ObligationCauseCode<'tcx> {
270270
parent_code: Lrc<ObligationCauseCode<'tcx>>,
271271
},
272272

273+
FunctionCallObligation {
274+
/// The node of the function call.
275+
call_hir_id: hir::HirId,
276+
/// The obligation introduced by this argument.
277+
parent_code: Lrc<ObligationCauseCode<'tcx>>,
278+
},
279+
273280
/// Error derived when matching traits/impls; see ObligationCause for more details
274281
CompareImplConstObligation,
275282

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,6 +2294,18 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
22942294
)
22952295
});
22962296
}
2297+
ObligationCauseCode::FunctionCallObligation { ref parent_code, .. } => {
2298+
ensure_sufficient_stack(|| {
2299+
self.note_obligation_cause_code(
2300+
err,
2301+
predicate,
2302+
param_env,
2303+
&parent_code,
2304+
obligated_types,
2305+
seen_requirements,
2306+
)
2307+
});
2308+
}
22972309
ObligationCauseCode::FunctionArgumentObligation {
22982310
arg_hir_id,
22992311
call_hir_id,

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11371137
} else if error.obligation.cause.span == call_sp {
11381138
// Make function calls point at the callee, not the whole thing.
11391139
if let hir::ExprKind::Call(callee, _) = expr.kind {
1140+
let parent_code = error.obligation.cause.clone_code();
1141+
*error.obligation.cause.make_mut_code() =
1142+
ObligationCauseCode::FunctionCallObligation {
1143+
call_hir_id: expr.hir_id,
1144+
parent_code,
1145+
};
11401146
error.obligation.cause.span = callee.span;
11411147
}
11421148
}

0 commit comments

Comments
 (0)