]> git.lizzy.rs Git - rust.git/blob - src/test/ui/parser/self-param-semantic-fail.rs
parser: address review comments re. `self`.
[rust.git] / src / test / ui / parser / self-param-semantic-fail.rs
1 // This test ensures that `self` is semantically rejected
2 // in contexts with `FnDecl` but outside of associated `fn`s.
3 // FIXME(Centril): For now closures are an exception.
4
5 fn main() {}
6
7 fn free() {
8     fn f1(self) {}
9     //~^ ERROR `self` parameter is only allowed in associated functions
10     fn f2(mut self) {}
11     //~^ ERROR `self` parameter is only allowed in associated functions
12     fn f3(&self) {}
13     //~^ ERROR `self` parameter is only allowed in associated functions
14     fn f4(&mut self) {}
15     //~^ ERROR `self` parameter is only allowed in associated functions
16     fn f5<'a>(&'a self) {}
17     //~^ ERROR `self` parameter is only allowed in associated functions
18     fn f6<'a>(&'a mut self) {}
19     //~^ ERROR `self` parameter is only allowed in associated functions
20     fn f7(self: u8) {}
21     //~^ ERROR `self` parameter is only allowed in associated functions
22     fn f8(mut self: u8) {}
23     //~^ ERROR `self` parameter is only allowed in associated functions
24 }
25
26 extern {
27     fn f1(self);
28     //~^ ERROR `self` parameter is only allowed in associated functions
29     fn f2(mut self);
30     //~^ ERROR `self` parameter is only allowed in associated functions
31     //~| ERROR patterns aren't allowed in
32     fn f3(&self);
33     //~^ ERROR `self` parameter is only allowed in associated functions
34     fn f4(&mut self);
35     //~^ ERROR `self` parameter is only allowed in associated functions
36     fn f5<'a>(&'a self);
37     //~^ ERROR `self` parameter is only allowed in associated functions
38     fn f6<'a>(&'a mut self);
39     //~^ ERROR `self` parameter is only allowed in associated functions
40     fn f7(self: u8);
41     //~^ ERROR `self` parameter is only allowed in associated functions
42     fn f8(mut self: u8);
43     //~^ ERROR `self` parameter is only allowed in associated functions
44     //~| ERROR patterns aren't allowed in
45 }
46
47 type X1 = fn(self);
48 //~^ ERROR `self` parameter is only allowed in associated functions
49 type X2 = fn(mut self);
50 //~^ ERROR `self` parameter is only allowed in associated functions
51 //~| ERROR patterns aren't allowed in
52 type X3 = fn(&self);
53 //~^ ERROR `self` parameter is only allowed in associated functions
54 type X4 = fn(&mut self);
55 //~^ ERROR `self` parameter is only allowed in associated functions
56 type X5 = for<'a> fn(&'a self);
57 //~^ ERROR `self` parameter is only allowed in associated functions
58 type X6 = for<'a> fn(&'a mut self);
59 //~^ ERROR `self` parameter is only allowed in associated functions
60 type X7 = fn(self: u8);
61 //~^ ERROR `self` parameter is only allowed in associated functions
62 type X8 = fn(mut self: u8);
63 //~^ ERROR `self` parameter is only allowed in associated functions
64 //~| ERROR patterns aren't allowed in