Implement CastKind::ClosureFnPointer
This commit is contained in:
parent
25f3ef5ff9
commit
89666d9818
@ -190,4 +190,6 @@ fn main() {
|
||||
[] => assert_eq!(0u32, 1),
|
||||
[_, ref y..] => assert_eq!(&x[1] as *const u32 as usize, &y[0] as *const u32 as usize),
|
||||
}
|
||||
|
||||
assert_eq!(((|()| 42u8) as fn(()) -> u8)(()), 42);
|
||||
}
|
||||
|
20
src/base.rs
20
src/base.rs
@ -586,8 +586,24 @@ fn trans_stmt<'a, 'tcx: 'a>(
|
||||
_ => unimpl!("rval misc {:?} {:?}", from_ty, to_ty),
|
||||
}
|
||||
}
|
||||
Rvalue::Cast(CastKind::ClosureFnPointer, operand, ty) => {
|
||||
unimplemented!("rval closure_fn_ptr {:?} {:?}", operand, ty)
|
||||
Rvalue::Cast(CastKind::ClosureFnPointer, operand, _ty) => {
|
||||
let operand = trans_operand(fx, operand);
|
||||
match operand.layout().ty.sty {
|
||||
ty::Closure(def_id, substs) => {
|
||||
let instance = rustc_mir::monomorphize::resolve_closure(
|
||||
fx.tcx,
|
||||
def_id,
|
||||
substs,
|
||||
ty::ClosureKind::FnOnce,
|
||||
);
|
||||
let func_ref = fx.get_function_ref(instance);
|
||||
let func_addr = fx.bcx.ins().func_addr(fx.pointer_type, func_ref);
|
||||
lval.write_cvalue(fx, CValue::ByVal(func_addr, lval.layout()));
|
||||
}
|
||||
_ => {
|
||||
bug!("{} cannot be cast to a fn ptr", operand.layout().ty)
|
||||
}
|
||||
}
|
||||
}
|
||||
Rvalue::Cast(CastKind::Unsize, operand, _ty) => {
|
||||
let operand = trans_operand(fx, operand);
|
||||
|
Loading…
x
Reference in New Issue
Block a user