@@ -467,6 +467,11 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
467
467
return ty;
468
468
}
469
469
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
+
470
475
// We try to be a little clever here as a performance optimization in
471
476
// cases where there are nested projections under binders.
472
477
// For example:
@@ -490,13 +495,11 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
490
495
// replace bound vars if the current type is a `Projection` and we need
491
496
// to make sure we don't forget to fold the substs regardless.
492
497
493
- match * ty . kind ( ) {
498
+ match kind {
494
499
// This is really important. While we *can* handle this, this has
495
500
// severe performance implications for large opaque types with
496
501
// 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 ( ) => {
500
503
// Only normalize `impl Trait` outside of type inference, usually in codegen.
501
504
match self . param_env . reveal ( ) {
502
505
Reveal :: UserFacing => ty. super_fold_with ( self ) ,
@@ -512,8 +515,8 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
512
515
) ;
513
516
}
514
517
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 ) ;
517
520
let concrete_ty = generic_ty. subst ( self . interner ( ) , substs) ;
518
521
self . depth += 1 ;
519
522
let folded_ty = self . fold_ty ( concrete_ty) ;
@@ -522,8 +525,9 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
522
525
}
523
526
}
524
527
}
528
+ ty:: Opaque => ty. super_fold_with ( self ) ,
525
529
526
- ty:: Alias ( ty :: Projection , data ) if !data. has_escaping_bound_vars ( ) => {
530
+ ty:: Projection if !data. has_escaping_bound_vars ( ) => {
527
531
// This branch is *mostly* just an optimization: when we don't
528
532
// have escaping bound vars, we don't need to replace them with
529
533
// 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
562
566
normalized_ty. ty ( ) . unwrap ( )
563
567
}
564
568
565
- ty:: Alias ( ty :: Projection , data ) => {
569
+ ty:: Projection => {
566
570
// If there are escaping bound vars, we temporarily replace the
567
571
// bound vars with placeholders. Note though, that in the case
568
572
// 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
611
615
) ;
612
616
normalized_ty
613
617
}
614
-
615
- _ => ty. super_fold_with ( self ) ,
616
618
}
617
619
}
618
620
0 commit comments