@@ -467,6 +467,11 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
467467 return ty;
468468 }
469469
470+ let ( kind, data) = match * ty. kind ( ) {
471+ ty:: Alias ( kind, alias_ty) => ( kind, alias_ty) ,
472+ _ => return ty. super_fold_with ( self ) ,
473+ } ;
474+
470475 // We try to be a little clever here as a performance optimization in
471476 // cases where there are nested projections under binders.
472477 // For example:
@@ -490,13 +495,11 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
490495 // replace bound vars if the current type is a `Projection` and we need
491496 // to make sure we don't forget to fold the substs regardless.
492497
493- match * ty . kind ( ) {
498+ match kind {
494499 // This is really important. While we *can* handle this, this has
495500 // severe performance implications for large opaque types with
496501 // late-bound regions. See `issue-88862` benchmark.
497- ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, substs, .. } )
498- if !substs. has_escaping_bound_vars ( ) =>
499- {
502+ ty:: Opaque if !data. substs . has_escaping_bound_vars ( ) => {
500503 // Only normalize `impl Trait` outside of type inference, usually in codegen.
501504 match self . param_env . reveal ( ) {
502505 Reveal :: UserFacing => ty. super_fold_with ( self ) ,
@@ -512,8 +515,8 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
512515 ) ;
513516 }
514517
515- let substs = substs. fold_with ( self ) ;
516- let generic_ty = self . interner ( ) . type_of ( def_id) ;
518+ let substs = data . substs . fold_with ( self ) ;
519+ let generic_ty = self . interner ( ) . type_of ( data . def_id ) ;
517520 let concrete_ty = generic_ty. subst ( self . interner ( ) , substs) ;
518521 self . depth += 1 ;
519522 let folded_ty = self . fold_ty ( concrete_ty) ;
@@ -522,8 +525,9 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
522525 }
523526 }
524527 }
528+ ty:: Opaque => ty. super_fold_with ( self ) ,
525529
526- ty:: Alias ( ty :: Projection , data ) if !data. has_escaping_bound_vars ( ) => {
530+ ty:: Projection if !data. has_escaping_bound_vars ( ) => {
527531 // This branch is *mostly* just an optimization: when we don't
528532 // have escaping bound vars, we don't need to replace them with
529533 // placeholders (see branch below). *Also*, we know that we can
@@ -562,7 +566,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
562566 normalized_ty. ty ( ) . unwrap ( )
563567 }
564568
565- ty:: Alias ( ty :: Projection , data ) => {
569+ ty:: Projection => {
566570 // If there are escaping bound vars, we temporarily replace the
567571 // bound vars with placeholders. Note though, that in the case
568572 // that we still can't project for whatever reason (e.g. self
@@ -611,8 +615,6 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
611615 ) ;
612616 normalized_ty
613617 }
614-
615- _ => ty. super_fold_with ( self ) ,
616618 }
617619 }
618620
0 commit comments