@@ -2760,21 +2760,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
2760
2760
// the implicit binder around the witness.
2761
2761
return types. skip_binder ( ) . to_vec ( )
2762
2762
}
2763
- // Note that we need to use optimized_mir here,
2764
- // in order to have the `StateTransform` pass run
2765
- /*let gen_mir = self.tcx().optimized_mir(did);
2766
- let gen_layout = gen_mir.generator_layout.as_ref()
2767
- .expect("Missing generator layout!");*/
2768
-
2769
- // We need to compare the types from the GeneratoWitness
2770
- // to the types from the MIR. Since the generator MIR (specifically
2771
- // the StateTransform pass) runs after lifetimes are erased, we must
2772
- // erase lifetime from our witness types in order to perform the comparsion
2763
+ // We ignore all regions when comparing the computed interior
2764
+ // MIR types to the witness types.
2765
+ //
2766
+ // We use `erase_late_bound_regions` to remove the outermost
2767
+ // layer of late-bound regions from the witness types.
2773
2768
//
2774
- // First, we erase all of late-bound regions bound by
2775
- // the witness type.
2776
- let unbound_tys = self . tcx ( ) . erase_late_bound_regions ( & types) ;
2777
-
2778
2769
// However, we may still have other regions within the inner
2779
2770
// witness type (eg.. 'static'). Thus, we need to call
2780
2771
// 'erase_regions' on each of the inner witness types.
@@ -2806,8 +2797,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
2806
2797
// Note that we need map erased types back to the orignal type.
2807
2798
// This allows to return the original type from the GeneratorWitness
2808
2799
// in our Vec of consiitutent types - preservering the internal regions
2809
- let erased_types: FxHashMap < _ , _ > = self . tcx ( ) . erase_regions ( & unbound_tys)
2810
- . into_iter ( )
2800
+ let erased_witness_types = self . tcx ( ) . erase_regions (
2801
+ & self . tcx ( ) . erase_late_bound_regions ( & types)
2802
+ ) ;
2803
+
2804
+ let erased_types: FxHashMap < _ , _ > = erased_witness_types. into_iter ( )
2811
2805
. zip ( types. skip_binder ( ) . into_iter ( ) )
2812
2806
. collect ( ) ;
2813
2807
@@ -2819,11 +2813,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
2819
2813
let interior_tys = self . tcx ( ) . optimized_mir ( did) . generator_interior_tys
2820
2814
. as_ref ( ) . expect ( "Missing generator interior types!" ) ;
2821
2815
2822
- //for ty in &gen_layout.field_tys {
2823
2816
for ty in interior_tys {
2824
- if let Some ( witness_ty) = erased_types. get ( & self . tcx ( ) . erase_regions ( ty) ) {
2825
- used_types. push ( * * witness_ty) ;
2826
- }
2817
+ let witness_ty = erased_types. get ( & self . tcx ( ) . erase_regions ( ty) )
2818
+ . unwrap_or_else ( || panic ! ( "Interior type {:?} not in {:?}" ,
2819
+ ty, erased_types) ) ;
2820
+
2821
+ used_types. push ( * * witness_ty) ;
2827
2822
}
2828
2823
2829
2824
debug ! ( "Used witness types for witness {:?} are: '{:?}'" , t, used_types) ;
0 commit comments