2015-06-14 19:07:05 -05:00
|
|
|
// Copyright 2014 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.
|
|
|
|
|
|
|
|
#![feature(core)]
|
|
|
|
use std::boxed::FnBox;
|
|
|
|
|
|
|
|
struct Obj<F> where F: FnOnce() -> u32 {
|
|
|
|
closure: F,
|
|
|
|
not_closure: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
struct BoxedObj {
|
|
|
|
boxed_closure: Box<FnBox() -> u32>,
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Wrapper<F> where F: FnMut() -> u32 {
|
|
|
|
wrap: Obj<F>,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn func() -> u32 {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_expression() -> Obj<Box<FnBox() -> u32>> {
|
|
|
|
Obj { closure: Box::new(|| 42_u32) as Box<FnBox() -> u32>, not_closure: 42 }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// test variations of function
|
2015-06-14 20:01:26 -05:00
|
|
|
|
2015-06-14 19:07:05 -05:00
|
|
|
let o_closure = Obj { closure: || 42, not_closure: 42 };
|
|
|
|
o_closure.closure(); //~ ERROR no method named `closure` found
|
2015-06-14 20:01:26 -05:00
|
|
|
//~^ NOTE use `(o_closure.closure)(...)` if you meant to call the function stored
|
2015-06-14 19:07:05 -05:00
|
|
|
|
|
|
|
o_closure.not_closure(); //~ ERROR no method named `not_closure` found
|
|
|
|
//~^ NOTE did you mean to write `o_closure.not_closure`?
|
|
|
|
|
|
|
|
let o_func = Obj { closure: func, not_closure: 5 };
|
|
|
|
o_func.closure(); //~ ERROR no method named `closure` found
|
2015-06-14 20:01:26 -05:00
|
|
|
//~^ NOTE use `(o_func.closure)(...)` if you meant to call the function stored
|
2015-06-14 19:07:05 -05:00
|
|
|
|
|
|
|
let boxed_fn = BoxedObj { boxed_closure: Box::new(func) };
|
|
|
|
boxed_fn.boxed_closure();//~ ERROR no method named `boxed_closure` found
|
2015-06-14 20:01:26 -05:00
|
|
|
//~^ NOTE use `(boxed_fn.boxed_closure)(...)` if you meant to call the function stored
|
2015-06-14 19:07:05 -05:00
|
|
|
|
|
|
|
let boxed_closure = BoxedObj { boxed_closure: Box::new(|| 42_u32) as Box<FnBox() -> u32> };
|
|
|
|
boxed_closure.boxed_closure();//~ ERROR no method named `boxed_closure` found
|
2015-06-14 20:01:26 -05:00
|
|
|
//~^ NOTE use `(boxed_closure.boxed_closure)(...)` if you meant to call the function stored
|
2015-06-14 19:07:05 -05:00
|
|
|
|
|
|
|
// test expression writing in the notes
|
2015-06-14 20:01:26 -05:00
|
|
|
|
2015-06-14 19:07:05 -05:00
|
|
|
let w = Wrapper { wrap: o_func };
|
|
|
|
w.wrap.closure();//~ ERROR no method named `closure` found
|
2015-06-14 20:01:26 -05:00
|
|
|
//~^ NOTE use `(w.wrap.closure)(...)` if you meant to call the function stored
|
|
|
|
|
2015-06-14 19:07:05 -05:00
|
|
|
w.wrap.not_closure();//~ ERROR no method named `not_closure` found
|
|
|
|
//~^ NOTE did you mean to write `w.wrap.not_closure`?
|
|
|
|
|
|
|
|
check_expression().closure();//~ ERROR no method named `closure` found
|
2015-06-14 20:01:26 -05:00
|
|
|
//~^ NOTE use `(check_expression().closure)(...)` if you meant to call the function stored
|
2015-06-14 19:07:05 -05:00
|
|
|
}
|