]> git.lizzy.rs Git - rust.git/blob - src/test/ui/confuse-field-and-method/issue-2392.rs
Merge commit '48d60ab7c505c6c1ebb042eacaafd8dc9f7a9267' into libgccjit-codegen
[rust.git] / src / test / ui / confuse-field-and-method / issue-2392.rs
1 struct FuncContainer {
2     f1: fn(data: u8),
3     f2: extern "C" fn(data: u8),
4     f3: unsafe fn(data: u8),
5 }
6
7 struct FuncContainerOuter {
8     container: Box<FuncContainer>
9 }
10
11 struct Obj<F> where F: FnOnce() -> u32 {
12     closure: F,
13     not_closure: usize,
14 }
15
16 struct BoxedObj {
17     boxed_closure: Box<dyn FnOnce() -> u32>,
18 }
19
20 struct Wrapper<F> where F: FnMut() -> u32 {
21     wrap: Obj<F>,
22 }
23
24 fn func() -> u32 {
25     0
26 }
27
28 fn check_expression() -> Obj<Box<dyn FnOnce() -> u32>> {
29     Obj { closure: Box::new(|| 42_u32) as Box<dyn FnOnce() -> u32>, not_closure: 42 }
30 }
31
32 fn main() {
33     // test variations of function
34
35     let o_closure = Obj { closure: || 42, not_closure: 42 };
36     o_closure.closure(); //~ ERROR no method named `closure` found
37
38     o_closure.not_closure();
39     //~^ ERROR no method named `not_closure` found
40
41     let o_func = Obj { closure: func, not_closure: 5 };
42     o_func.closure(); //~ ERROR no method named `closure` found
43
44     let boxed_fn = BoxedObj { boxed_closure: Box::new(func) };
45     boxed_fn.boxed_closure();//~ ERROR no method named `boxed_closure` found
46
47     let boxed_closure = BoxedObj { boxed_closure: Box::new(|| 42_u32) as Box<dyn FnOnce() -> u32> };
48     boxed_closure.boxed_closure();//~ ERROR no method named `boxed_closure` found
49
50     // test expression writing in the notes
51
52     let w = Wrapper { wrap: o_func };
53     w.wrap.closure();//~ ERROR no method named `closure` found
54
55     w.wrap.not_closure();
56     //~^ ERROR no method named `not_closure` found
57
58     check_expression().closure();//~ ERROR no method named `closure` found
59 }
60
61 impl FuncContainerOuter {
62     fn run(&self) {
63         unsafe {
64             (*self.container).f1(1); //~ ERROR no method named `f1` found
65             (*self.container).f2(1); //~ ERROR no method named `f2` found
66             (*self.container).f3(1); //~ ERROR no method named `f3` found
67         }
68     }
69 }