rust/tests/ui/unboxed-closures/unboxed-closures-boxed.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

15 lines
288 B
Rust
Raw Normal View History

//@ run-pass
2019-05-28 18:47:21 +00:00
fn make_adder(x: i32) -> Box<dyn FnMut(i32)->i32+'static> {
Box::new(move |y: i32| -> i32 { x + y }) as
2019-05-28 18:47:21 +00:00
Box<dyn FnMut(i32)->i32+'static>
}
pub fn main() {
let mut adder = make_adder(3);
let z = adder(2);
println!("{}", z);
assert_eq!(z, 5);
}