Skip to content

Commit c005e76

Browse files
Rework point-at-arg
1 parent fb80d2b commit c005e76

File tree

155 files changed

+1269
-782
lines changed

Some content is hidden

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

155 files changed

+1269
-782
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");

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,10 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
211211
);
212212
let mut err = self.tcx().sess.struct_span_err(span, &msg);
213213

214-
let leading_ellipsis = if let ObligationCauseCode::ItemObligation(def_id) = *cause.code() {
214+
let leading_ellipsis = if let ObligationCauseCode::ItemObligation(def_id)
215+
| ObligationCauseCode::ExprItemObligation(def_id, ..) =
216+
*cause.code()
217+
{
215218
err.span_label(span, "doesn't satisfy where-clause");
216219
err.span_label(
217220
self.tcx().def_span(def_id),

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
232232
ObligationCauseCode::MatchImpl(parent, ..) => parent.code(),
233233
_ => cause.code(),
234234
}
235-
&& let (&ObligationCauseCode::ItemObligation(item_def_id), None) = (code, override_error_code)
235+
&& let (&ObligationCauseCode::ItemObligation(item_def_id) | &ObligationCauseCode::ExprItemObligation(item_def_id, ..), None) = (code, override_error_code)
236236
{
237237
// Same case of `impl Foo for dyn Bar { fn qux(&self) {} }` introducing a `'static`
238238
// lifetime as above, but called using a fully-qualified path to the method:

compiler/rustc_infer/src/infer/error_reporting/note.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
390390
if matches!(
391391
&trace.cause.code().peel_derives(),
392392
ObligationCauseCode::BindingObligation(..)
393+
| ObligationCauseCode::ExprBindingObligation(..)
393394
) =>
394395
{
395396
// Hack to get around the borrow checker because trace.cause has an `Rc`.
396-
if let ObligationCauseCode::BindingObligation(_, span) =
397+
if let ObligationCauseCode::BindingObligation(_, span)
398+
| ObligationCauseCode::ExprBindingObligation(_, span, ..) =
397399
&trace.cause.code().peel_derives()
398400
{
399401
let span = *span;

compiler/rustc_infer/src/infer/outlives/obligations.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
9797
cause.span,
9898
sup_type,
9999
match cause.code().peel_derives() {
100-
ObligationCauseCode::BindingObligation(_, span) => Some(*span),
100+
ObligationCauseCode::BindingObligation(_, span)
101+
| ObligationCauseCode::ExprBindingObligation(_, span, ..) => Some(*span),
101102
_ => None,
102103
},
103104
)

compiler/rustc_middle/src/traits/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,13 @@ pub enum ObligationCauseCode<'tcx> {
238238
/// also implement all supertraits of `X`.
239239
ItemObligation(DefId),
240240

241+
ExprItemObligation(DefId, rustc_hir::HirId, usize),
242+
241243
/// Like `ItemObligation`, but with extra detail on the source of the obligation.
242244
BindingObligation(DefId, Span),
243245

246+
ExprBindingObligation(DefId, Span, rustc_hir::HirId, usize),
247+
244248
/// A type like `&'a T` is WF only if `T: 'a`.
245249
ReferenceOutlivesReferent(Ty<'tcx>),
246250

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
15641564
obligation.cause.code().peel_derives(),
15651565
ObligationCauseCode::ItemObligation(_)
15661566
| ObligationCauseCode::BindingObligation(_, _)
1567+
| ObligationCauseCode::ExprItemObligation(..)
1568+
| ObligationCauseCode::ExprBindingObligation(..)
15671569
| ObligationCauseCode::ObjectCastObligation(..)
15681570
| ObligationCauseCode::OpaqueType
15691571
);
@@ -2091,13 +2093,11 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
20912093
}
20922094
}
20932095

2094-
if let ObligationCauseCode::ItemObligation(def_id) = *obligation.cause.code() {
2096+
if let ObligationCauseCode::ItemObligation(def_id) | ObligationCauseCode::ExprItemObligation(def_id, ..) = *obligation.cause.code() {
20952097
self.suggest_fully_qualified_path(&mut err, def_id, span, trait_ref.def_id());
2096-
} else if let (
2097-
Ok(ref snippet),
2098-
&ObligationCauseCode::BindingObligation(def_id, _),
2099-
) =
2100-
(self.tcx.sess.source_map().span_to_snippet(span), obligation.cause.code())
2098+
} else if let Ok(snippet) = &self.tcx.sess.source_map().span_to_snippet(span)
2099+
&& let ObligationCauseCode::BindingObligation(def_id, _) | ObligationCauseCode::ExprBindingObligation(def_id, ..)
2100+
= *obligation.cause.code()
21012101
{
21022102
let generics = self.tcx.generics_of(def_id);
21032103
if generics.params.iter().any(|p| p.name != kw::SelfUpper)
@@ -2520,15 +2520,10 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
25202520
err: &mut Diagnostic,
25212521
obligation: &PredicateObligation<'tcx>,
25222522
) {
2523-
let (
2524-
ty::PredicateKind::Trait(pred),
2525-
&ObligationCauseCode::BindingObligation(item_def_id, span),
2526-
) = (
2527-
obligation.predicate.kind().skip_binder(),
2528-
obligation.cause.code().peel_derives(),
2529-
) else {
2530-
return;
2531-
};
2523+
let ty::PredicateKind::Trait(pred) = obligation.predicate.kind().skip_binder() else { return; };
2524+
let (ObligationCauseCode::BindingObligation(item_def_id, span)
2525+
| ObligationCauseCode::ExprBindingObligation(item_def_id, span, ..))
2526+
= *obligation.cause.code().peel_derives() else { return; };
25322527
debug!(?pred, ?item_def_id, ?span);
25332528

25342529
let (Some(node), true) = (

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
143143
}
144144

145145
if let ObligationCauseCode::ItemObligation(item)
146-
| ObligationCauseCode::BindingObligation(item, _) = *obligation.cause.code()
146+
| ObligationCauseCode::BindingObligation(item, _)
147+
| ObligationCauseCode::ExprItemObligation(item, ..)
148+
| ObligationCauseCode::ExprBindingObligation(item, ..) = *obligation.cause.code()
147149
{
148150
// FIXME: maybe also have some way of handling methods
149151
// from other traits? That would require name resolution,

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
10221022
if let ObligationCauseCode::ImplDerivedObligation(cause) = &*code {
10231023
try_borrowing(cause.derived.parent_trait_pred, &[])
10241024
} else if let ObligationCauseCode::BindingObligation(_, _)
1025-
| ObligationCauseCode::ItemObligation(..) = code
1025+
| ObligationCauseCode::ItemObligation(_)
1026+
| ObligationCauseCode::ExprItemObligation(..)
1027+
| ObligationCauseCode::ExprBindingObligation(..) = code
10261028
{
10271029
try_borrowing(poly_trait_pred, &never_suggest_borrow)
10281030
} else {
@@ -2244,11 +2246,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
22442246
region, object_ty,
22452247
));
22462248
}
2247-
ObligationCauseCode::ItemObligation(_item_def_id) => {
2249+
ObligationCauseCode::ItemObligation(_)
2250+
| ObligationCauseCode::ExprItemObligation(..) => {
22482251
// We hold the `DefId` of the item introducing the obligation, but displaying it
22492252
// doesn't add user usable information. It always point at an associated item.
22502253
}
2251-
ObligationCauseCode::BindingObligation(item_def_id, span) => {
2254+
ObligationCauseCode::BindingObligation(item_def_id, span)
2255+
| ObligationCauseCode::ExprBindingObligation(item_def_id, span, ..) => {
22522256
let item_name = tcx.def_path_str(item_def_id);
22532257
let mut multispan = MultiSpan::from(span);
22542258
if let Some(ident) = tcx.opt_item_ident(item_def_id) {

0 commit comments

Comments
 (0)