@@ -492,25 +492,6 @@ fn polymorphize<'tcx>(
492
492
let unused = tcx. unused_generic_params ( def_id) ;
493
493
debug ! ( "polymorphize: unused={:?}" , unused) ;
494
494
495
- if unused. is_empty ( ) {
496
- // Exit early if every parameter was used.
497
- return substs;
498
- }
499
-
500
- // If this is a closure or generator then we need to handle the case where another closure
501
- // from the function is captured as an upvar and hasn't been polymorphized. In this case,
502
- // the unpolymorphized upvar closure would result in a polymorphized closure producing
503
- // multiple mono items (and eventually symbol clashes).
504
- let upvars_ty = if tcx. is_closure ( def_id) {
505
- Some ( substs. as_closure ( ) . tupled_upvars_ty ( ) )
506
- } else if tcx. type_of ( def_id) . is_generator ( ) {
507
- Some ( substs. as_generator ( ) . tupled_upvars_ty ( ) )
508
- } else {
509
- None
510
- } ;
511
- let has_upvars = upvars_ty. map ( |ty| ty. tuple_fields ( ) . count ( ) > 0 ) . unwrap_or ( false ) ;
512
- debug ! ( "polymorphize: upvars_ty={:?} has_upvars={:?}" , upvars_ty, has_upvars) ;
513
-
514
495
struct PolymorphizationFolder < ' tcx > {
515
496
tcx : TyCtxt < ' tcx > ,
516
497
} ;
@@ -540,31 +521,20 @@ fn polymorphize<'tcx>(
540
521
let is_unused = unused. contains ( param. index ) . unwrap_or ( false ) ;
541
522
debug ! ( "polymorphize: param={:?} is_unused={:?}" , param, is_unused) ;
542
523
match param. kind {
543
- // Upvar case: If parameter is a type parameter..
544
- ty:: GenericParamDefKind :: Type { .. } if
545
- // ..and has upvars..
546
- has_upvars &&
547
- // ..and this param has the same type as the tupled upvars..
548
- upvars_ty == Some ( substs[ param. index as usize ] . expect_ty ( ) ) => {
549
- // ..then double-check that polymorphization marked it used..
550
- debug_assert ! ( !is_unused) ;
551
- // ..and polymorphize any closures/generators captured as upvars.
552
- let upvars_ty = upvars_ty. unwrap ( ) ;
553
- let polymorphized_upvars_ty = upvars_ty. fold_with (
554
- & mut PolymorphizationFolder { tcx } ) ;
555
- debug ! ( "polymorphize: polymorphized_upvars_ty={:?}" , polymorphized_upvars_ty) ;
556
- ty:: GenericArg :: from ( polymorphized_upvars_ty)
557
- } ,
558
-
559
- // Simple case: If parameter is a const or type parameter..
524
+ // If parameter is a const or type parameter..
560
525
ty:: GenericParamDefKind :: Const | ty:: GenericParamDefKind :: Type { .. } if
561
526
// ..and is within range and unused..
562
527
unused. contains ( param. index ) . unwrap_or ( false ) =>
563
528
// ..then use the identity for this parameter.
564
529
tcx. mk_param_from_def ( param) ,
565
530
566
- // Otherwise, use the parameter as before.
567
- _ => substs[ param. index as usize ] ,
531
+ // Otherwise, use the parameter as before (polymorphizing any closures or generators).
532
+ _ => {
533
+ let arg = substs[ param. index as usize ] ;
534
+ let polymorphized_arg = arg. fold_with ( & mut PolymorphizationFolder { tcx } ) ;
535
+ debug ! ( "polymorphize: arg={:?} polymorphized_arg={:?}" , arg, polymorphized_arg) ;
536
+ ty:: GenericArg :: from ( polymorphized_arg)
537
+ }
568
538
}
569
539
} )
570
540
}
0 commit comments