@@ -93,37 +93,42 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
9393 } ;
9494
9595 // Guard against `<T as Trait<?0>>::Assoc = ?0>`.
96- struct ContainsTerm < ' tcx > {
96+ struct ContainsTerm < ' a , ' tcx > {
9797 term : ty:: Term < ' tcx > ,
98+ infcx : & ' a InferCtxt < ' tcx > ,
9899 }
99- impl < ' tcx > TypeVisitor < TyCtxt < ' tcx > > for ContainsTerm < ' tcx > {
100+ impl < ' tcx > TypeVisitor < TyCtxt < ' tcx > > for ContainsTerm < ' _ , ' tcx > {
100101 type BreakTy = ( ) ;
101102 fn visit_ty ( & mut self , t : Ty < ' tcx > ) -> ControlFlow < Self :: BreakTy > {
102- if t. needs_infer ( ) {
103- if ty:: Term :: from ( t) == self . term {
104- ControlFlow :: Break ( ( ) )
105- } else {
106- t. super_visit_with ( self )
107- }
103+ if let Some ( vid) = t. ty_vid ( )
104+ && let ty:: TermKind :: Ty ( term) = self . term . unpack ( )
105+ && let Some ( term_vid) = term. ty_vid ( )
106+ && self . infcx . root_var ( vid) == self . infcx . root_var ( term_vid)
107+ {
108+ ControlFlow :: Break ( ( ) )
109+ } else if t. has_non_region_infer ( ) {
110+ t. super_visit_with ( self )
108111 } else {
109112 ControlFlow :: Continue ( ( ) )
110113 }
111114 }
112115
113116 fn visit_const ( & mut self , c : ty:: Const < ' tcx > ) -> ControlFlow < Self :: BreakTy > {
114- if c. needs_infer ( ) {
115- if ty:: Term :: from ( c) == self . term {
116- ControlFlow :: Break ( ( ) )
117- } else {
118- c. super_visit_with ( self )
119- }
117+ if let ty:: ConstKind :: Infer ( ty:: InferConst :: Var ( vid) ) = c. kind ( )
118+ && let ty:: TermKind :: Const ( term) = self . term . unpack ( )
119+ && let ty:: ConstKind :: Infer ( ty:: InferConst :: Var ( term_vid) ) = term. kind ( )
120+ && self . infcx . root_const_var ( vid) == self . infcx . root_const_var ( term_vid)
121+ {
122+ ControlFlow :: Break ( ( ) )
123+ } else if c. has_non_region_infer ( ) {
124+ c. super_visit_with ( self )
120125 } else {
121126 ControlFlow :: Continue ( ( ) )
122127 }
123128 }
124129 }
125130
126- let mut visitor = ContainsTerm { term : goal. predicate . term } ;
131+ let mut visitor = ContainsTerm { infcx : self . infcx , term : goal. predicate . term } ;
127132
128133 term_is_infer
129134 && goal. predicate . projection_ty . visit_with ( & mut visitor) . is_continue ( )
0 commit comments