Skip to content

Commit 87fc30d

Browse files
committed
Cleanup trait selection logic
1 parent b891e49 commit 87fc30d

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

src/librustc/traits/select.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2760,21 +2760,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
27602760
// the implicit binder around the witness.
27612761
return types.skip_binder().to_vec()
27622762
}
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.
27732768
//
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-
27782769
// However, we may still have other regions within the inner
27792770
// witness type (eg.. 'static'). Thus, we need to call
27802771
// 'erase_regions' on each of the inner witness types.
@@ -2806,8 +2797,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
28062797
// Note that we need map erased types back to the orignal type.
28072798
// This allows to return the original type from the GeneratorWitness
28082799
// 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()
28112805
.zip(types.skip_binder().into_iter())
28122806
.collect();
28132807

@@ -2819,11 +2813,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
28192813
let interior_tys = self.tcx().optimized_mir(did).generator_interior_tys
28202814
.as_ref().expect("Missing generator interior types!");
28212815

2822-
//for ty in &gen_layout.field_tys {
28232816
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);
28272822
}
28282823

28292824
debug!("Used witness types for witness {:?} are: '{:?}'", t, used_types);

0 commit comments

Comments
 (0)