diff options
Diffstat (limited to 'src/librustc_codegen_llvm/meth.rs')
| -rw-r--r-- | src/librustc_codegen_llvm/meth.rs | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/src/librustc_codegen_llvm/meth.rs b/src/librustc_codegen_llvm/meth.rs index 8a1159bc477..db06b87f44e 100644 --- a/src/librustc_codegen_llvm/meth.rs +++ b/src/librustc_codegen_llvm/meth.rs @@ -72,7 +72,7 @@ impl<'a, 'tcx> VirtualIndex { pub fn get_vtable( cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>, - trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>, + trait_ref: ty::PolyExistentialTraitRef<'tcx>, ) -> &'ll Value { let tcx = cx.tcx; @@ -86,23 +86,19 @@ pub fn get_vtable( // Not in the cache. Build it. let nullptr = C_null(Type::i8p(cx)); + let methods = tcx.vtable_methods(trait_ref.with_self_ty(tcx, ty)); + let methods = methods.iter().cloned().map(|opt_mth| { + opt_mth.map_or(nullptr, |(def_id, substs)| { + callee::resolve_and_get_fn(cx, def_id, substs) + }) + }); + let (size, align) = cx.size_and_align_of(ty); - let mut components: Vec<_> = [ + let components: Vec<_> = [ callee::get_fn(cx, monomorphize::resolve_drop_in_place(cx.tcx, ty)), C_usize(cx, size.bytes()), C_usize(cx, align.abi()) - ].iter().cloned().collect(); - - if let Some(trait_ref) = trait_ref { - let trait_ref = trait_ref.with_self_ty(tcx, ty); - let methods = tcx.vtable_methods(trait_ref); - let methods = methods.iter().cloned().map(|opt_mth| { - opt_mth.map_or(nullptr, |(def_id, substs)| { - callee::resolve_and_get_fn(cx, def_id, substs) - }) - }); - components.extend(methods); - } + ].iter().cloned().chain(methods).collect(); let vtable_const = C_struct(cx, &components, false); let align = cx.data_layout().pointer_align; |
