diff --git a/src/interpreter/vtable.rs b/src/interpreter/vtable.rs index 9892da0bdb5b..201bedc1a862 100644 --- a/src/interpreter/vtable.rs +++ b/src/interpreter/vtable.rs @@ -58,11 +58,14 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { } traits::VtableFnPointer( traits::VtableFnPointerData { - fn_ty: _bare_fn_ty, + fn_ty, nested: _ }) => { - let _trait_closure_kind = tcx.lang_items.fn_trait_kind(trait_ref.def_id()).unwrap(); - //vec![trans_fn_pointer_shim(ccx, trait_closure_kind, bare_fn_ty)].into_iter() - unimplemented!() + match fn_ty.sty { + ty::TyFnDef(did, substs, bare_fn_ty) => { + vec![Some(self.memory.create_fn_ptr(did, substs, bare_fn_ty))].into_iter() + }, + _ => bug!("bad VtableFnPointer fn_ty: {:?}", fn_ty), + } } traits::VtableObject(ref data) => { // this would imply that the Self type being erased is diff --git a/tests/run-pass/issue-30530.rs b/tests/run-pass/issue-30530.rs new file mode 100644 index 000000000000..d5139c908bda --- /dev/null +++ b/tests/run-pass/issue-30530.rs @@ -0,0 +1,35 @@ +// Copyright 2012-2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Regression test for Issue #30530: alloca's created for storing +// intermediate scratch values during brace-less match arms need to be +// initialized with their drop-flag set to "dropped" (or else we end +// up running the destructors on garbage data at the end of the +// function). + +pub enum Handler { + Default, + #[allow(dead_code)] + Custom(*mut Box), +} + +fn main() { + take(Handler::Default, Box::new(main)); +} + +#[inline(never)] +pub fn take(h: Handler, f: Box) -> Box { + unsafe { + match h { + Handler::Custom(ptr) => *Box::from_raw(ptr), + Handler::Default => f, + } + } +}