@@ -5,7 +5,7 @@ use rustc_infer::infer::{outlives::env::OutlivesEnvironment, TyCtxtInferExt};
5
5
use rustc_lint_defs:: builtin:: REFINING_IMPL_TRAIT ;
6
6
use rustc_middle:: traits:: { ObligationCause , Reveal } ;
7
7
use rustc_middle:: ty:: {
8
- self , Ty , TyCtxt , TypeFoldable , TypeSuperVisitable , TypeVisitable , TypeVisitor ,
8
+ self , Ty , TyCtxt , TypeFoldable , TypeFolder , TypeSuperVisitable , TypeVisitable , TypeVisitor ,
9
9
} ;
10
10
use rustc_span:: { Span , DUMMY_SP } ;
11
11
use rustc_trait_selection:: traits:: {
@@ -176,9 +176,13 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
176
176
return ;
177
177
} ;
178
178
179
- // For quicker lookup, use an `IndexSet`
180
- // (we don't use one earlier because it's not foldable..)
181
- let trait_bounds = FxIndexSet :: from_iter ( trait_bounds) ;
179
+ // For quicker lookup, use an `IndexSet` (we don't use one earlier because
180
+ // it's not foldable..).
181
+ // Also, We have to anonymize binders in these types because they may contain
182
+ // `BrNamed` bound vars, which contain unique `DefId`s which correspond to syntax
183
+ // locations that we don't care about when checking bound equality.
184
+ let trait_bounds = FxIndexSet :: from_iter ( trait_bounds. fold_with ( & mut Anonymize { tcx } ) ) ;
185
+ let impl_bounds = impl_bounds. fold_with ( & mut Anonymize { tcx } ) ;
182
186
183
187
// Find any clauses that are present in the impl's RPITITs that are not
184
188
// present in the trait's RPITITs. This will trigger on trivial predicates,
@@ -309,3 +313,20 @@ fn type_visibility<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<ty::Visibili
309
313
_ => None ,
310
314
}
311
315
}
316
+
317
+ struct Anonymize < ' tcx > {
318
+ tcx : TyCtxt < ' tcx > ,
319
+ }
320
+
321
+ impl < ' tcx > TypeFolder < TyCtxt < ' tcx > > for Anonymize < ' tcx > {
322
+ fn interner ( & self ) -> TyCtxt < ' tcx > {
323
+ self . tcx
324
+ }
325
+
326
+ fn fold_binder < T > ( & mut self , t : ty:: Binder < ' tcx , T > ) -> ty:: Binder < ' tcx , T >
327
+ where
328
+ T : TypeFoldable < TyCtxt < ' tcx > > ,
329
+ {
330
+ self . tcx . anonymize_bound_vars ( t)
331
+ }
332
+ }
0 commit comments