@@ -2,8 +2,8 @@ use rustc_type_ir::data_structures::ensure_sufficient_stack;
22use rustc_type_ir:: inherent:: * ;
33use rustc_type_ir:: solve:: { Goal , NoSolution } ;
44use rustc_type_ir:: {
5- self as ty, Binder , FallibleTypeFolder , InferConst , InferCtxtLike , InferTy , Interner ,
6- TypeFoldable , TypeSuperFoldable , TypeSuperVisitable , TypeVisitable , TypeVisitableExt ,
5+ self as ty, AliasTerm , Binder , FallibleTypeFolder , InferConst , InferCtxtLike , InferTy ,
6+ Interner , TypeFoldable , TypeSuperFoldable , TypeSuperVisitable , TypeVisitable , TypeVisitableExt ,
77 TypeVisitor , UniverseIndex ,
88} ;
99use tracing:: instrument;
@@ -101,7 +101,7 @@ impl<'a, Infcx, I, F> NormalizationFolder<'a, Infcx, I, F>
101101where
102102 Infcx : InferCtxtLike < Interner = I > ,
103103 I : Interner ,
104- F : FnMut ( I :: Term ) -> Result < ( I :: Term , Option < Goal < I , I :: Predicate > > ) , NoSolution > ,
104+ F : FnMut ( AliasTerm < I > ) -> Result < ( I :: Term , Option < Goal < I , I :: Predicate > > ) , NoSolution > ,
105105{
106106 pub fn new (
107107 infcx : & ' a Infcx ,
@@ -118,7 +118,7 @@ where
118118
119119 fn normalize_alias_term (
120120 & mut self ,
121- alias_term : I :: Term ,
121+ alias_term : AliasTerm < I > ,
122122 has_escaping : HasEscapingBoundVars ,
123123 ) -> Result < I :: Term , NoSolution > {
124124 let current_universe = self . infcx . universe ( ) ;
@@ -139,7 +139,7 @@ where
139139 normalized. visit_with ( & mut visitor) ;
140140 let max_universe = visitor. max_universe ( ) ;
141141 if current_universe. cannot_name ( max_universe) {
142- return Ok ( alias_term) ;
142+ return Ok ( alias_term. to_term ( self . cx ( ) ) ) ;
143143 }
144144 }
145145
@@ -152,7 +152,7 @@ impl<'a, Infcx, I, F> FallibleTypeFolder<I> for NormalizationFolder<'a, Infcx, I
152152where
153153 Infcx : InferCtxtLike < Interner = I > ,
154154 I : Interner ,
155- F : FnMut ( I :: Term ) -> Result < ( I :: Term , Option < Goal < I , I :: Predicate > > ) , NoSolution > ,
155+ F : FnMut ( AliasTerm < I > ) -> Result < ( I :: Term , Option < Goal < I , I :: Predicate > > ) , NoSolution > ,
156156{
157157 type Error = NoSolution ;
158158
@@ -180,13 +180,13 @@ where
180180 // With eager normalization, we should normalize the args of alias before
181181 // normalizing the alias itself.
182182 let ty = ty. try_super_fold_with ( self ) ?;
183- let ty:: Alias ( .. ) = ty. kind ( ) else { return Ok ( ty) } ;
183+ let ty:: Alias ( alias_ty ) = ty. kind ( ) else { return Ok ( ty) } ;
184184
185185 if ty. has_escaping_bound_vars ( ) {
186- let ( ty , mapped_regions, mapped_types, mapped_consts) =
187- BoundVarReplacer :: replace_bound_vars ( infcx, & mut self . universes , ty ) ;
186+ let ( alias_ty , mapped_regions, mapped_types, mapped_consts) =
187+ BoundVarReplacer :: replace_bound_vars ( infcx, & mut self . universes , alias_ty ) ;
188188 let result = ensure_sufficient_stack ( || {
189- self . normalize_alias_term ( ty . into ( ) , HasEscapingBoundVars :: Yes )
189+ self . normalize_alias_term ( alias_ty . into ( ) , HasEscapingBoundVars :: Yes )
190190 } ) ?
191191 . expect_ty ( ) ;
192192 Ok ( PlaceholderReplacer :: replace_placeholders (
@@ -199,7 +199,7 @@ where
199199 ) )
200200 } else {
201201 Ok ( ensure_sufficient_stack ( || {
202- self . normalize_alias_term ( ty . into ( ) , HasEscapingBoundVars :: No )
202+ self . normalize_alias_term ( alias_ty . into ( ) , HasEscapingBoundVars :: No )
203203 } ) ?
204204 . expect_ty ( ) )
205205 }
@@ -215,13 +215,17 @@ where
215215 // With eager normalization, we should normalize the args of alias before
216216 // normalizing the alias itself.
217217 let ct = ct. try_super_fold_with ( self ) ?;
218- let ty:: ConstKind :: Unevaluated ( ..) = ct. kind ( ) else { return Ok ( ct) } ;
218+ let ty:: ConstKind :: Unevaluated ( uc) = ct. kind ( ) else { return Ok ( ct) } ;
219+ let cx = self . cx ( ) ;
219220
220221 if ct. has_escaping_bound_vars ( ) {
221- let ( ct , mapped_regions, mapped_types, mapped_consts) =
222- BoundVarReplacer :: replace_bound_vars ( infcx, & mut self . universes , ct ) ;
222+ let ( uc , mapped_regions, mapped_types, mapped_consts) =
223+ BoundVarReplacer :: replace_bound_vars ( infcx, & mut self . universes , uc ) ;
223224 let result = ensure_sufficient_stack ( || {
224- self . normalize_alias_term ( ct. into ( ) , HasEscapingBoundVars :: Yes )
225+ self . normalize_alias_term (
226+ AliasTerm :: from_unevaluated_const ( cx, uc) ,
227+ HasEscapingBoundVars :: Yes ,
228+ )
225229 } ) ?
226230 . expect_const ( ) ;
227231 Ok ( PlaceholderReplacer :: replace_placeholders (
@@ -234,7 +238,10 @@ where
234238 ) )
235239 } else {
236240 Ok ( ensure_sufficient_stack ( || {
237- self . normalize_alias_term ( ct. into ( ) , HasEscapingBoundVars :: No )
241+ self . normalize_alias_term (
242+ AliasTerm :: from_unevaluated_const ( cx, uc) ,
243+ HasEscapingBoundVars :: No ,
244+ )
238245 } ) ?
239246 . expect_const ( ) )
240247 }
0 commit comments