@@ -5,7 +5,7 @@ use rustc_infer::infer::{outlives::env::OutlivesEnvironment, TyCtxtInferExt};
55use rustc_lint_defs:: builtin:: REFINING_IMPL_TRAIT ;
66use rustc_middle:: traits:: { ObligationCause , Reveal } ;
77use rustc_middle:: ty:: {
8- self , Ty , TyCtxt , TypeFoldable , TypeSuperVisitable , TypeVisitable , TypeVisitor ,
8+ self , Ty , TyCtxt , TypeFoldable , TypeFolder , TypeSuperVisitable , TypeVisitable , TypeVisitor ,
99} ;
1010use rustc_span:: { Span , DUMMY_SP } ;
1111use rustc_trait_selection:: traits:: {
@@ -176,9 +176,13 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
176176 return ;
177177 } ;
178178
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 } ) ;
182186
183187 // Find any clauses that are present in the impl's RPITITs that are not
184188 // 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
309313 _ => None ,
310314 }
311315}
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