Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0b71ffc

Browse files
committedAug 21, 2022
Auto merge of #100654 - compiler-errors:rework-point-at-arg, r=estebank
Rework "point at arg" suggestions to be more accurate Fixes #100560 Introduce a new set of `ObligationCauseCode`s which have additional bookeeping for what expression caused the obligation, and which predicate caused the obligation. This allows us to look at the _unsubstituted_ signature to find out which parameter or generic type argument caused an obligaton to fail. This means that (in most cases) we significantly improve the likelihood of pointing out the right argument that causes a fulfillment error. Also, since this logic isn't happening in just the `select_where_possible_and_mutate_fulfillment()` calls in the argument checking code, but instead during all trait selection in `FnCtxt`, we are also able to point out the correct argument even if inference means that we don't know whether an obligation has failed until well after a call expression has been checked. r? `@ghost`
2 parents c0941df + d577eb0 commit 0b71ffc

File tree

161 files changed

+1369
-780
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+1369
-780
lines changed
 

‎compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -740,12 +740,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
740740
err.help("...or use `match` instead of `let...else`");
741741
}
742742
_ => {
743-
if let ObligationCauseCode::BindingObligation(_, binding_span) =
744-
cause.code().peel_derives()
743+
if let ObligationCauseCode::BindingObligation(_, span)
744+
| ObligationCauseCode::ExprBindingObligation(_, span, ..)
745+
= cause.code().peel_derives()
746+
&& let TypeError::RegionsPlaceholderMismatch = terr
745747
{
746-
if matches!(terr, TypeError::RegionsPlaceholderMismatch) {
747-
err.span_note(*binding_span, "the lifetime requirement is introduced here");
748-
}
748+
err.span_note(*span, "the lifetime requirement is introduced here");
749749
}
750750
}
751751
}

‎compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mismatched_static_lifetime.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
3535
let ObligationCauseCode::MatchImpl(parent, impl_def_id) = code else {
3636
return None;
3737
};
38-
let ObligationCauseCode::BindingObligation(_def_id, binding_span) = *parent.code() else {
38+
let (ObligationCauseCode::BindingObligation(_, binding_span) | ObligationCauseCode::ExprBindingObligation(_, binding_span, ..))
39+
= *parent.code() else {
3940
return None;
4041
};
4142
let mut err = self.tcx().sess.struct_span_err(cause.span, "incompatible lifetime on type");

0 commit comments

Comments
 (0)
Please sign in to comment.