@@ -8,7 +8,7 @@ use rustc_infer::infer::InferCtxt;
88use  rustc_infer:: traits:: TraitEngineExt ; 
99use  rustc_infer:: traits:: { FulfillmentError ,  Obligation ,  TraitEngine } ; 
1010use  rustc_middle:: infer:: unify_key:: { ConstVariableOrigin ,  ConstVariableOriginKind } ; 
11- use  rustc_middle:: traits:: { ObligationCause ,   Reveal } ; 
11+ use  rustc_middle:: traits:: ObligationCause ; 
1212use  rustc_middle:: ty:: { self ,  AliasTy ,  Ty ,  TyCtxt ,  UniverseIndex } ; 
1313use  rustc_middle:: ty:: { FallibleTypeFolder ,  TypeFolder ,  TypeSuperFoldable } ; 
1414use  rustc_middle:: ty:: { TypeFoldable ,  TypeVisitableExt } ; 
@@ -52,14 +52,16 @@ struct NormalizationFolder<'me, 'tcx> {
5252impl < ' tcx >  NormalizationFolder < ' _ ,  ' tcx >  { 
5353    fn  normalize_alias_ty ( 
5454        & mut  self , 
55-         alias :   AliasTy < ' tcx > , 
55+         alias_ty :   Ty < ' tcx > , 
5656    )  -> Result < Ty < ' tcx > ,  Vec < FulfillmentError < ' tcx > > >  { 
57+         assert ! ( matches!( alias_ty. kind( ) ,  ty:: Alias ( ..) ) ) ; 
58+ 
5759        let  infcx = self . at . infcx ; 
5860        let  tcx = infcx. tcx ; 
5961        let  recursion_limit = tcx. recursion_limit ( ) ; 
6062        if  !recursion_limit. value_within_limit ( self . depth )  { 
6163            self . at . infcx . err_ctxt ( ) . report_overflow_error ( 
62-                 & alias . to_ty ( tcx ) , 
64+                 & alias_ty , 
6365                self . at . cause . span , 
6466                true , 
6567                |_| { } , 
@@ -76,7 +78,11 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
7678            tcx, 
7779            self . at . cause . clone ( ) , 
7880            self . at . param_env , 
79-             ty:: NormalizesTo  {  alias,  term :  new_infer_ty. into ( )  } , 
81+             ty:: PredicateKind :: AliasRelate ( 
82+                 alias_ty. into ( ) , 
83+                 new_infer_ty. into ( ) , 
84+                 ty:: AliasRelationDirection :: Equate , 
85+             ) , 
8086        ) ; 
8187
8288        // Do not emit an error if normalization is known to fail but instead 
@@ -90,9 +96,12 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
9096                return  Err ( errors) ; 
9197            } 
9298            let  ty = infcx. resolve_vars_if_possible ( new_infer_ty) ; 
93-             ty. try_fold_with ( self ) ?
99+ 
100+             // Alias is guaranteed to be fully structurally resolved, 
101+             // so we can super fold here. 
102+             ty. try_super_fold_with ( self ) ?
94103        }  else  { 
95-             alias . to_ty ( tcx ) . try_super_fold_with ( self ) ?
104+             alias_ty . try_super_fold_with ( self ) ?
96105        } ; 
97106
98107        self . depth  -= 1 ; 
@@ -170,24 +179,18 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for NormalizationFolder<'_, 'tcx> {
170179    } 
171180
172181    fn  try_fold_ty ( & mut  self ,  ty :  Ty < ' tcx > )  -> Result < Ty < ' tcx > ,  Self :: Error >  { 
173-         let  reveal = self . at . param_env . reveal ( ) ; 
174182        let  infcx = self . at . infcx ; 
175183        debug_assert_eq ! ( ty,  infcx. shallow_resolve( ty) ) ; 
176-         if  !needs_normalization ( & ty ,  reveal )  { 
184+         if  !ty . has_projections ( )  { 
177185            return  Ok ( ty) ; 
178186        } 
179187
180-         // We don't normalize opaque types unless we have 
181-         // `Reveal::All`, even if we're in the defining scope. 
182-         let  data = match  * ty. kind ( )  { 
183-             ty:: Alias ( kind,  alias_ty)  if  kind != ty:: Opaque  || reveal == Reveal :: All  => alias_ty, 
184-             _ => return  ty. try_super_fold_with ( self ) , 
185-         } ; 
188+         let  ty:: Alias ( ..)  = * ty. kind ( )  else  {  return  ty. try_super_fold_with ( self )  } ; 
186189
187-         if  data . has_escaping_bound_vars ( )  { 
188-             let  ( data ,  mapped_regions,  mapped_types,  mapped_consts)  =
189-                 BoundVarReplacer :: replace_bound_vars ( infcx,  & mut  self . universes ,  data ) ; 
190-             let  result = ensure_sufficient_stack ( || self . normalize_alias_ty ( data ) ) ?; 
190+         if  ty . has_escaping_bound_vars ( )  { 
191+             let  ( ty ,  mapped_regions,  mapped_types,  mapped_consts)  =
192+                 BoundVarReplacer :: replace_bound_vars ( infcx,  & mut  self . universes ,  ty ) ; 
193+             let  result = ensure_sufficient_stack ( || self . normalize_alias_ty ( ty ) ) ?; 
191194            Ok ( PlaceholderReplacer :: replace_placeholders ( 
192195                infcx, 
193196                mapped_regions, 
@@ -197,7 +200,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for NormalizationFolder<'_, 'tcx> {
197200                result, 
198201            ) ) 
199202        }  else  { 
200-             ensure_sufficient_stack ( || self . normalize_alias_ty ( data ) ) 
203+             ensure_sufficient_stack ( || self . normalize_alias_ty ( ty ) ) 
201204        } 
202205    } 
203206
0 commit comments