@@ -13,6 +13,7 @@ use rustc_middle::ty::{
13
13
use rustc_span:: { ErrorGuaranteed , Span } ;
14
14
use rustc_trait_selection:: error_reporting:: traits:: report_object_safety_error;
15
15
use rustc_trait_selection:: traits:: { self , hir_ty_lowering_object_safety_violations} ;
16
+ use rustc_type_ir:: elaborate:: ClauseWithSupertraitSpan ;
16
17
use smallvec:: { smallvec, SmallVec } ;
17
18
use tracing:: { debug, instrument} ;
18
19
@@ -124,16 +125,19 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
124
125
. into_iter ( )
125
126
. filter ( |( trait_ref, _) | !tcx. trait_is_auto ( trait_ref. def_id ( ) ) ) ;
126
127
127
- for ( base_trait_ref, span ) in regular_traits_refs_spans {
128
+ for ( base_trait_ref, original_span ) in regular_traits_refs_spans {
128
129
let base_pred: ty:: Predicate < ' tcx > = base_trait_ref. upcast ( tcx) ;
129
- for pred in traits:: elaborate ( tcx, [ base_pred] ) . filter_only_self ( ) {
130
+ for ClauseWithSupertraitSpan { pred, original_span, supertrait_span } in
131
+ traits:: elaborate ( tcx, [ ClauseWithSupertraitSpan :: new ( base_pred, original_span) ] )
132
+ . filter_only_self ( )
133
+ {
130
134
debug ! ( "observing object predicate `{pred:?}`" ) ;
131
135
132
136
let bound_predicate = pred. kind ( ) ;
133
137
match bound_predicate. skip_binder ( ) {
134
138
ty:: PredicateKind :: Clause ( ty:: ClauseKind :: Trait ( pred) ) => {
135
139
let pred = bound_predicate. rebind ( pred) ;
136
- associated_types. entry ( span ) . or_default ( ) . extend (
140
+ associated_types. entry ( original_span ) . or_default ( ) . extend (
137
141
tcx. associated_items ( pred. def_id ( ) )
138
142
. in_definition_order ( )
139
143
. filter ( |item| item. kind == ty:: AssocKind :: Type )
@@ -172,10 +176,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
172
176
// the discussion in #56288 for alternatives.
173
177
if !references_self {
174
178
// Include projections defined on supertraits.
175
- projection_bounds. push ( ( pred, span ) ) ;
179
+ projection_bounds. push ( ( pred, original_span ) ) ;
176
180
}
177
181
178
- self . check_elaborated_projection_mentions_input_lifetimes ( pred, span) ;
182
+ self . check_elaborated_projection_mentions_input_lifetimes (
183
+ pred,
184
+ original_span,
185
+ supertrait_span,
186
+ ) ;
179
187
}
180
188
_ => ( ) ,
181
189
}
@@ -369,6 +377,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
369
377
& self ,
370
378
pred : ty:: PolyProjectionPredicate < ' tcx > ,
371
379
span : Span ,
380
+ supertrait_span : Span ,
372
381
) {
373
382
let tcx = self . tcx ( ) ;
374
383
@@ -405,6 +414,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
405
414
item_name,
406
415
br_name
407
416
)
417
+ . with_span_label ( supertrait_span, "due to this supertrait" )
408
418
} ,
409
419
) ;
410
420
}
0 commit comments