Closed
Description
#![feature(core)]
use std::boxed::{FnBox};
type Closure = Box<FnBox(i32)>;
type ClosureReference = Box<FnBox(&i32)>;
fn works(closure: Closure) {
closure(42);
}
fn does_not_work(closure: ClosureReference) {
closure(&42); // <- the error
}
fn main() {
works(Box::new(|integer| println!("{}", integer)));
does_not_work(Box::new(|integer: &i32| println!("{}", integer)));
}
Error
<anon>:13:5: 13:17 error: expected function, found `Box<for<'r> alloc::boxed::FnBox<(&'r i32,), Output=()>>`
<anon>:13 closure(&42); // <- the error
^~~~~~~~~~~~
On a semi-related note, the closure argument type is inferred for the Closure
passed to works
but not for the ClosureReference
passed to does_not_work
, but I think this is likely an extension of #24680.
Meta
rustc 1.2.0-nightly (c23a9d42e 2015-05-17) (built 2015-05-17)
binary: rustc
commit-hash: c23a9d42ea082830593a73d25821842baf9ccf33
commit-date: 2015-05-17
build-date: 2015-05-17
host: x86_64-pc-windows-gnu
release: 1.2.0-nightly