@@ -293,6 +293,18 @@ where
293
293
result
294
294
}
295
295
296
+ pub ( crate ) fn needs_normalization < ' tcx , T : TypeFoldable < ' tcx > > ( value : & T , reveal : Reveal ) -> bool {
297
+ match reveal {
298
+ Reveal :: UserFacing => value
299
+ . has_type_flags ( ty:: TypeFlags :: HAS_TY_PROJECTION | ty:: TypeFlags :: HAS_CT_PROJECTION ) ,
300
+ Reveal :: All => value. has_type_flags (
301
+ ty:: TypeFlags :: HAS_TY_PROJECTION
302
+ | ty:: TypeFlags :: HAS_TY_OPAQUE
303
+ | ty:: TypeFlags :: HAS_CT_PROJECTION ,
304
+ ) ,
305
+ }
306
+ }
307
+
296
308
struct AssocTypeNormalizer < ' a , ' b , ' tcx > {
297
309
selcx : & ' a mut SelectionContext < ' b , ' tcx > ,
298
310
param_env : ty:: ParamEnv < ' tcx > ,
@@ -323,7 +335,11 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
323
335
value
324
336
) ;
325
337
326
- if !value. has_projections ( ) { value } else { value. fold_with ( self ) }
338
+ if !needs_normalization ( & value, self . param_env . reveal ( ) ) {
339
+ value
340
+ } else {
341
+ value. fold_with ( self )
342
+ }
327
343
}
328
344
}
329
345
@@ -343,7 +359,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
343
359
}
344
360
345
361
fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
346
- if !ty . has_projections ( ) {
362
+ if !needs_normalization ( & ty , self . param_env . reveal ( ) ) {
347
363
return ty;
348
364
}
349
365
// We don't want to normalize associated types that occur inside of region
0 commit comments