@@ -194,7 +194,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
194194 // wait to fold the substs.
195195
196196 // Wrap this in a closure so we don't accidentally return from the outer function
197- let mut res = ( || match * ty. kind ( ) {
197+ let res = ( || match * ty. kind ( ) {
198198 // This is really important. While we *can* handle this, this has
199199 // severe performance implications for large opaque types with
200200 // late-bound regions. See `issue-88862` benchmark.
@@ -266,7 +266,15 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
266266 debug ! ( "QueryNormalizer: result = {:#?}" , result) ;
267267 debug ! ( "QueryNormalizer: obligations = {:#?}" , obligations) ;
268268 self . obligations . extend ( obligations) ;
269- Ok ( result. normalized_ty )
269+
270+ let res = result. normalized_ty ;
271+ // `tcx.normalize_projection_ty` may normalize to a type that still has
272+ // unevaluated consts, so keep normalizing here if that's the case.
273+ if res != ty && res. has_type_flags ( ty:: TypeFlags :: HAS_CT_PROJECTION ) {
274+ Ok ( res. try_super_fold_with ( self ) ?)
275+ } else {
276+ Ok ( res)
277+ }
270278 }
271279
272280 ty:: Projection ( data) => {
@@ -305,25 +313,27 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
305313 debug ! ( "QueryNormalizer: result = {:#?}" , result) ;
306314 debug ! ( "QueryNormalizer: obligations = {:#?}" , obligations) ;
307315 self . obligations . extend ( obligations) ;
308- Ok ( crate :: traits:: project:: PlaceholderReplacer :: replace_placeholders (
316+
317+ let res = crate :: traits:: project:: PlaceholderReplacer :: replace_placeholders (
309318 infcx,
310319 mapped_regions,
311320 mapped_types,
312321 mapped_consts,
313322 & self . universes ,
314323 result. normalized_ty ,
315- ) )
324+ ) ;
325+ // `tcx.normalize_projection_ty` may normalize to a type that still has
326+ // unevaluated consts, so keep normalizing here if that's the case.
327+ if res != ty && res. has_type_flags ( ty:: TypeFlags :: HAS_CT_PROJECTION ) {
328+ Ok ( res. try_super_fold_with ( self ) ?)
329+ } else {
330+ Ok ( res)
331+ }
316332 }
317333
318334 _ => ty. try_super_fold_with ( self ) ,
319335 } ) ( ) ?;
320336
321- // `tcx.normalize_projection_ty` may normalize to a type that still has
322- // unevaluated consts, so keep normalizing here if that's the case.
323- if res != ty && res. has_type_flags ( ty:: TypeFlags :: HAS_CT_PROJECTION ) {
324- res = res. try_super_fold_with ( self ) ?;
325- }
326-
327337 self . cache . insert ( ty, res) ;
328338 Ok ( res)
329339 }
0 commit comments