1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![feature(core, fnbox)]
13 use std::boxed::FnBox;
15 struct FuncContainer {
17 f2: extern "C" fn(data: u8),
18 f3: unsafe fn(data: u8),
21 struct FuncContainerOuter {
22 container: Box<FuncContainer>
25 struct Obj<F> where F: FnOnce() -> u32 {
31 boxed_closure: Box<FnBox() -> u32>,
34 struct Wrapper<F> where F: FnMut() -> u32 {
42 fn check_expression() -> Obj<Box<FnBox() -> u32>> {
43 Obj { closure: Box::new(|| 42_u32) as Box<FnBox() -> u32>, not_closure: 42 }
47 // test variations of function
49 let o_closure = Obj { closure: || 42, not_closure: 42 };
50 o_closure.closure(); //~ ERROR no method named `closure` found
52 o_closure.not_closure();
53 //~^ ERROR no method named `not_closure` found
55 let o_func = Obj { closure: func, not_closure: 5 };
56 o_func.closure(); //~ ERROR no method named `closure` found
58 let boxed_fn = BoxedObj { boxed_closure: Box::new(func) };
59 boxed_fn.boxed_closure();//~ ERROR no method named `boxed_closure` found
61 let boxed_closure = BoxedObj { boxed_closure: Box::new(|| 42_u32) as Box<FnBox() -> u32> };
62 boxed_closure.boxed_closure();//~ ERROR no method named `boxed_closure` found
64 // test expression writing in the notes
66 let w = Wrapper { wrap: o_func };
67 w.wrap.closure();//~ ERROR no method named `closure` found
70 //~^ ERROR no method named `not_closure` found
72 check_expression().closure();//~ ERROR no method named `closure` found
75 impl FuncContainerOuter {
78 (*self.container).f1(1); //~ ERROR no method named `f1` found
79 (*self.container).f2(1); //~ ERROR no method named `f2` found
80 (*self.container).f3(1); //~ ERROR no method named `f3` found