implement fn item -> trait object conversion
This commit is contained in:
parent
1c5c6cd078
commit
64155ffd10
2 changed files with 42 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
35
tests/run-pass/issue-30530.rs
Normal file
35
tests/run-pass/issue-30530.rs
Normal file
|
|
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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()>),
|
||||
}
|
||||
|
||||
fn main() {
|
||||
take(Handler::Default, Box::new(main));
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
pub fn take(h: Handler, f: Box<Fn()>) -> Box<Fn()> {
|
||||
unsafe {
|
||||
match h {
|
||||
Handler::Custom(ptr) => *Box::from_raw(ptr),
|
||||
Handler::Default => f,
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue