@@ -293,6 +293,18 @@ where
293293 result
294294}
295295
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+
296308struct AssocTypeNormalizer < ' a , ' b , ' tcx > {
297309 selcx : & ' a mut SelectionContext < ' b , ' tcx > ,
298310 param_env : ty:: ParamEnv < ' tcx > ,
@@ -323,7 +335,11 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
323335 value
324336 ) ;
325337
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+ }
327343 }
328344}
329345
@@ -343,7 +359,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
343359 }
344360
345361 fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
346- if !ty . has_projections ( ) {
362+ if !needs_normalization ( & ty , self . param_env . reveal ( ) ) {
347363 return ty;
348364 }
349365 // We don't want to normalize associated types that occur inside of region
0 commit comments