|
1 | 1 | use crate::traits::*;
|
2 | 2 |
|
3 |
| -use rustc_middle::ty::{self, subst::GenericArgKind, ExistentialPredicate, Ty, TyCtxt}; |
| 3 | +use rustc_middle::ty::{self, subst::GenericArgKind, Ty}; |
4 | 4 | use rustc_session::config::Lto;
|
5 | 5 | use rustc_symbol_mangling::typeid_for_trait_ref;
|
6 | 6 | use rustc_target::abi::call::FnAbi;
|
@@ -29,7 +29,7 @@ impl<'a, 'tcx> VirtualIndex {
|
29 | 29 | && bx.cx().sess().lto() == Lto::Fat
|
30 | 30 | {
|
31 | 31 | let typeid =
|
32 |
| - bx.typeid_metadata(typeid_for_trait_ref(bx.tcx(), get_trait_ref(bx.tcx(), ty))); |
| 32 | + bx.typeid_metadata(typeid_for_trait_ref(bx.tcx(), expect_dyn_trait_in_self(ty))); |
33 | 33 | let vtable_byte_offset = self.0 * bx.data_layout().pointer_size.bytes();
|
34 | 34 | let type_checked_load = bx.type_checked_load(llvtable, vtable_byte_offset, typeid);
|
35 | 35 | let func = bx.extract_value(type_checked_load, 0);
|
@@ -64,17 +64,13 @@ impl<'a, 'tcx> VirtualIndex {
|
64 | 64 | }
|
65 | 65 | }
|
66 | 66 |
|
67 |
| -fn get_trait_ref<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::PolyExistentialTraitRef<'tcx> { |
| 67 | +/// This takes a valid `self` receiver type and extracts the principal trait |
| 68 | +/// ref of the type. |
| 69 | +fn expect_dyn_trait_in_self<'tcx>(ty: Ty<'tcx>) -> ty::PolyExistentialTraitRef<'tcx> { |
68 | 70 | for arg in ty.peel_refs().walk() {
|
69 | 71 | if let GenericArgKind::Type(ty) = arg.unpack() {
|
70 |
| - if let ty::Dynamic(trait_refs, _) = ty.kind() { |
71 |
| - return trait_refs[0].map_bound(|trait_ref| match trait_ref { |
72 |
| - ExistentialPredicate::Trait(tr) => tr, |
73 |
| - ExistentialPredicate::Projection(proj) => proj.trait_ref(tcx), |
74 |
| - ExistentialPredicate::AutoTrait(_) => { |
75 |
| - bug!("auto traits don't have functions") |
76 |
| - } |
77 |
| - }); |
| 72 | + if let ty::Dynamic(data, _) = ty.kind() { |
| 73 | + return data.principal().expect("expected principal trait object"); |
78 | 74 | }
|
79 | 75 | }
|
80 | 76 | }
|
|
0 commit comments