Skip to content

rustc_typeck: add obligation cause code for function call #94036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what this PR really does.
Which obligation code was previously used for this case?
Can this new code make any observable changes in tests?
Also call_hir_id is set here but never used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which obligation code was previously used for this case?

That's the problem: almost any obligation code could have been previously used for this case. This code is used in any case where a function call introduces an obligation, but the obligation cannot be tracked down to a particular function parameter, so the function callee itself is used for the span.

Can this new code make any observable changes in tests?

It doesn't, no.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the problem: almost any obligation code could have been previously used for this case.

Why is that a problem though?
Why is it necessary to wrap the parent obligation into something instead of using it directly? Especially if it is not observable from the outside.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure.

@estebank what else did you want done here?

error.obligation.cause.span = callee.span;
}
}
Expand Down