11//! Deeply normalize types using the old trait solver. 
22
33use  rustc_data_structures:: stack:: ensure_sufficient_stack; 
4- use  rustc_infer:: infer:: InferOk ; 
54use  rustc_infer:: infer:: at:: At ; 
5+ use  rustc_infer:: infer:: { InferCtxt ,  InferOk } ; 
66use  rustc_infer:: traits:: { 
77    FromSolverError ,  Normalized ,  Obligation ,  PredicateObligations ,  TraitEngine , 
88} ; 
99use  rustc_macros:: extension; 
10- use  rustc_middle:: traits:: { ObligationCause ,  ObligationCauseCode ,   Reveal } ; 
10+ use  rustc_middle:: traits:: { ObligationCause ,  ObligationCauseCode } ; 
1111use  rustc_middle:: ty:: { 
1212    self ,  Ty ,  TyCtxt ,  TypeFoldable ,  TypeFolder ,  TypeSuperFoldable ,  TypeVisitable ,  TypeVisitableExt , 
13+     TypingMode , 
1314} ; 
1415use  tracing:: { debug,  instrument} ; 
1516
@@ -109,16 +110,19 @@ where
109110} 
110111
111112pub ( super )  fn  needs_normalization < ' tcx ,  T :  TypeVisitable < TyCtxt < ' tcx > > > ( 
113+     infcx :  & InferCtxt < ' tcx > , 
114+     param_env_for_debug_assertion :  ty:: ParamEnv < ' tcx > , 
112115    value :  & T , 
113-     reveal :  Reveal , 
114116)  -> bool  { 
115117    let  mut  flags = ty:: TypeFlags :: HAS_ALIAS ; 
116118
117119    // Opaques are treated as rigid with `Reveal::UserFacing`, 
118120    // so we can ignore those. 
119-     match  reveal { 
120-         Reveal :: UserFacing  => flags. remove ( ty:: TypeFlags :: HAS_TY_OPAQUE ) , 
121-         Reveal :: All  => { } 
121+     match  infcx. typing_mode ( param_env_for_debug_assertion)  { 
122+         TypingMode :: Coherence  | TypingMode :: Analysis  {  defining_opaque_types :  _ }  => { 
123+             flags. remove ( ty:: TypeFlags :: HAS_TY_OPAQUE ) 
124+         } 
125+         TypingMode :: PostAnalysis  => { } 
122126    } 
123127
124128    value. has_type_flags ( flags) 
@@ -154,7 +158,7 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
154158            "Normalizing {value:?} without wrapping in a `Binder`" 
155159        ) ; 
156160
157-         if  !needs_normalization ( & value ,  self . param_env . reveal ( ) )  { 
161+         if  !needs_normalization ( self . selcx . infcx ,  self . param_env ,   & value )  { 
158162            value
159163        }  else  { 
160164            value. fold_with ( self ) 
@@ -178,7 +182,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
178182    } 
179183
180184    fn  fold_ty ( & mut  self ,  ty :  Ty < ' tcx > )  -> Ty < ' tcx >  { 
181-         if  !needs_normalization ( & ty ,  self . param_env . reveal ( ) )  { 
185+         if  !needs_normalization ( self . selcx . infcx ,  self . param_env ,   & ty )  { 
182186            return  ty; 
183187        } 
184188
@@ -213,10 +217,11 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
213217        match  kind { 
214218            ty:: Opaque  => { 
215219                // Only normalize `impl Trait` outside of type inference, usually in codegen. 
216-                 match  self . param_env . reveal ( )  { 
217-                     Reveal :: UserFacing  => ty. super_fold_with ( self ) , 
218- 
219-                     Reveal :: All  => { 
220+                 match  self . selcx . infcx . typing_mode ( self . param_env )  { 
221+                     TypingMode :: Coherence  | TypingMode :: Analysis  {  defining_opaque_types :  _ }  => { 
222+                         ty. super_fold_with ( self ) 
223+                     } 
224+                     TypingMode :: PostAnalysis  => { 
220225                        let  recursion_limit = self . cx ( ) . recursion_limit ( ) ; 
221226                        if  !recursion_limit. value_within_limit ( self . depth )  { 
222227                            self . selcx . infcx . err_ctxt ( ) . report_overflow_error ( 
@@ -403,7 +408,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
403408    fn  fold_const ( & mut  self ,  constant :  ty:: Const < ' tcx > )  -> ty:: Const < ' tcx >  { 
404409        let  tcx = self . selcx . tcx ( ) ; 
405410        if  tcx. features ( ) . generic_const_exprs ( ) 
406-             || !needs_normalization ( & constant ,  self . param_env . reveal ( ) ) 
411+             || !needs_normalization ( self . selcx . infcx ,  self . param_env ,   & constant ) 
407412        { 
408413            constant
409414        }  else  { 
@@ -420,7 +425,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
420425
421426    #[ inline]  
422427    fn  fold_predicate ( & mut  self ,  p :  ty:: Predicate < ' tcx > )  -> ty:: Predicate < ' tcx >  { 
423-         if  p. allow_normalization ( )  && needs_normalization ( & p ,  self . param_env . reveal ( ) )  { 
428+         if  p. allow_normalization ( )  && needs_normalization ( self . selcx . infcx ,  self . param_env ,   & p )  { 
424429            p. super_fold_with ( self ) 
425430        }  else  { 
426431            p
0 commit comments