]> git.lizzy.rs Git - rust.git/blob - src/test/ui/confuse-field-and-method/issue-2392.rs
Auto merge of #54624 - arielb1:evaluate-outlives, r=nikomatsakis
[rust.git] / src / test / ui / confuse-field-and-method / issue-2392.rs
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.
4 //
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.
10
11 #![feature(core, fnbox)]
12
13 use std::boxed::FnBox;
14
15 struct FuncContainer {
16     f1: fn(data: u8),
17     f2: extern "C" fn(data: u8),
18     f3: unsafe fn(data: u8),
19 }
20
21 struct FuncContainerOuter {
22     container: Box<FuncContainer>
23 }
24
25 struct Obj<F> where F: FnOnce() -> u32 {
26     closure: F,
27     not_closure: usize,
28 }
29
30 struct BoxedObj {
31     boxed_closure: Box<FnBox() -> u32>,
32 }
33
34 struct Wrapper<F> where F: FnMut() -> u32 {
35     wrap: Obj<F>,
36 }
37
38 fn func() -> u32 {
39     0
40 }
41
42 fn check_expression() -> Obj<Box<FnBox() -> u32>> {
43     Obj { closure: Box::new(|| 42_u32) as Box<FnBox() -> u32>, not_closure: 42 }
44 }
45
46 fn main() {
47     // test variations of function
48
49     let o_closure = Obj { closure: || 42, not_closure: 42 };
50     o_closure.closure(); //~ ERROR no method named `closure` found
51
52     o_closure.not_closure();
53     //~^ ERROR no method named `not_closure` found
54
55     let o_func = Obj { closure: func, not_closure: 5 };
56     o_func.closure(); //~ ERROR no method named `closure` found
57
58     let boxed_fn = BoxedObj { boxed_closure: Box::new(func) };
59     boxed_fn.boxed_closure();//~ ERROR no method named `boxed_closure` found
60
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
63
64     // test expression writing in the notes
65
66     let w = Wrapper { wrap: o_func };
67     w.wrap.closure();//~ ERROR no method named `closure` found
68
69     w.wrap.not_closure();
70     //~^ ERROR no method named `not_closure` found
71
72     check_expression().closure();//~ ERROR no method named `closure` found
73 }
74
75 impl FuncContainerOuter {
76     fn run(&self) {
77         unsafe {
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
81         }
82     }
83 }