Skip to content

Commit

Permalink
rustc_typeck: add obligation cause code for function call
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Feb 15, 2022
1 parent bfb2856 commit 3ca2ba0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ pub enum ObligationCauseCode<'tcx> {
parent_code: Lrc<ObligationCauseCode<'tcx>>,
},

FunctionCallObligation {
/// The node of the function call.
call_hir_id: hir::HirId,
/// The obligation introduced by this argument.
parent_code: Lrc<ObligationCauseCode<'tcx>>,
},

/// Error derived when matching traits/impls; see ObligationCause for more details
CompareImplConstObligation,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 3ca2ba0

Please sign in to comment.