1
1
//! Deeply normalize types using the old trait solver.
2
2
3
3
use rustc_data_structures:: stack:: ensure_sufficient_stack;
4
- use rustc_infer:: infer:: InferOk ;
5
4
use rustc_infer:: infer:: at:: At ;
5
+ use rustc_infer:: infer:: { InferCtxt , InferOk } ;
6
6
use rustc_infer:: traits:: {
7
7
FromSolverError , Normalized , Obligation , PredicateObligations , TraitEngine ,
8
8
} ;
9
9
use rustc_macros:: extension;
10
- use rustc_middle:: traits:: { ObligationCause , ObligationCauseCode , Reveal } ;
10
+ use rustc_middle:: traits:: { ObligationCause , ObligationCauseCode } ;
11
11
use rustc_middle:: ty:: {
12
12
self , Ty , TyCtxt , TypeFoldable , TypeFolder , TypeSuperFoldable , TypeVisitable , TypeVisitableExt ,
13
+ TypingMode ,
13
14
} ;
14
15
use tracing:: { debug, instrument} ;
15
16
@@ -109,16 +110,19 @@ where
109
110
}
110
111
111
112
pub ( super ) fn needs_normalization < ' tcx , T : TypeVisitable < TyCtxt < ' tcx > > > (
113
+ infcx : & InferCtxt < ' tcx > ,
114
+ param_env_for_debug_assertion : ty:: ParamEnv < ' tcx > ,
112
115
value : & T ,
113
- reveal : Reveal ,
114
116
) -> bool {
115
117
let mut flags = ty:: TypeFlags :: HAS_ALIAS ;
116
118
117
119
// Opaques are treated as rigid with `Reveal::UserFacing`,
118
120
// 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 => { }
122
126
}
123
127
124
128
value. has_type_flags ( flags)
@@ -154,7 +158,7 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
154
158
"Normalizing {value:?} without wrapping in a `Binder`"
155
159
) ;
156
160
157
- if !needs_normalization ( & value , self . param_env . reveal ( ) ) {
161
+ if !needs_normalization ( self . selcx . infcx , self . param_env , & value ) {
158
162
value
159
163
} else {
160
164
value. fold_with ( self )
@@ -178,7 +182,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
178
182
}
179
183
180
184
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 ) {
182
186
return ty;
183
187
}
184
188
@@ -213,10 +217,11 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
213
217
match kind {
214
218
ty:: Opaque => {
215
219
// 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 => {
220
225
let recursion_limit = self . cx ( ) . recursion_limit ( ) ;
221
226
if !recursion_limit. value_within_limit ( self . depth ) {
222
227
self . selcx . infcx . err_ctxt ( ) . report_overflow_error (
@@ -403,7 +408,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
403
408
fn fold_const ( & mut self , constant : ty:: Const < ' tcx > ) -> ty:: Const < ' tcx > {
404
409
let tcx = self . selcx . tcx ( ) ;
405
410
if tcx. features ( ) . generic_const_exprs ( )
406
- || !needs_normalization ( & constant , self . param_env . reveal ( ) )
411
+ || !needs_normalization ( self . selcx . infcx , self . param_env , & constant )
407
412
{
408
413
constant
409
414
} else {
@@ -420,7 +425,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
420
425
421
426
#[ inline]
422
427
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 ) {
424
429
p. super_fold_with ( self )
425
430
} else {
426
431
p
0 commit comments