From 3aa1503a61d03834643a39f3e4c9de6721c31bdb Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Tue, 4 Dec 2018 13:28:06 +0200 Subject: add support for principal-less trait object types should be a pure refactoring. --- src/librustc_codegen_ssa/meth.rs | 13 ++++++++++--- src/librustc_codegen_ssa/traits/misc.rs | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'src/librustc_codegen_ssa') diff --git a/src/librustc_codegen_ssa/meth.rs b/src/librustc_codegen_ssa/meth.rs index 31640826262..98ad2616eea 100644 --- a/src/librustc_codegen_ssa/meth.rs +++ b/src/librustc_codegen_ssa/meth.rs @@ -69,7 +69,7 @@ impl<'a, 'tcx: 'a> VirtualIndex { pub fn get_vtable<'tcx, Cx: CodegenMethods<'tcx>>( cx: &Cx, ty: Ty<'tcx>, - trait_ref: ty::PolyExistentialTraitRef<'tcx>, + trait_ref: Option>, ) -> Cx::Value { let tcx = cx.tcx(); @@ -83,8 +83,15 @@ pub fn get_vtable<'tcx, Cx: CodegenMethods<'tcx>>( // Not in the cache. Build it. let nullptr = cx.const_null(cx.type_i8p()); - let methods = tcx.vtable_methods(trait_ref.with_self_ty(tcx, ty)); - let methods = methods.iter().cloned().map(|opt_mth| { + let methods_root; + let methods = if let Some(trait_ref) = trait_ref { + methods_root = tcx.vtable_methods(trait_ref.with_self_ty(tcx, ty)); + methods_root.iter() + } else { + (&[]).iter() + }; + + let methods = methods.cloned().map(|opt_mth| { opt_mth.map_or(nullptr, |(def_id, substs)| { callee::resolve_and_get_fn_for_vtable(cx, def_id, substs) }) diff --git a/src/librustc_codegen_ssa/traits/misc.rs b/src/librustc_codegen_ssa/traits/misc.rs index c297288b255..b2315556366 100644 --- a/src/librustc_codegen_ssa/traits/misc.rs +++ b/src/librustc_codegen_ssa/traits/misc.rs @@ -11,7 +11,7 @@ use std::sync::Arc; pub trait MiscMethods<'tcx>: BackendTypes { fn vtables( &self, - ) -> &RefCell, ty::PolyExistentialTraitRef<'tcx>), Self::Value>>; + ) -> &RefCell, Option>), Self::Value>>; fn check_overflow(&self) -> bool; fn instances(&self) -> &RefCell, Self::Value>>; fn get_fn(&self, instance: Instance<'tcx>) -> Self::Value; -- cgit 1.4.1-3-g733a5