]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/issue-2356.rs
Rollup merge of #35876 - matthew-piziak:sub-examples, r=GuillaumeGomez
[rust.git] / src / test / compile-fail / issue-2356.rs
1 // Copyright 2012-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 trait Groom {
12     fn shave(other: usize);
13 }
14
15 pub struct cat {
16   whiskers: isize,
17 }
18
19 pub enum MaybeDog {
20     Dog,
21     NoDog
22 }
23
24 impl MaybeDog {
25   fn bark() {
26     // If this provides a suggestion, it's a bug as MaybeDog doesn't impl Groom
27     shave();
28     //~^ ERROR: unresolved name `shave`
29   }
30 }
31
32 impl Groom for cat {
33   fn shave(other: usize) {
34     whiskers -= other;
35     //~^ ERROR: unresolved name `whiskers`
36     //~| HELP this is an associated function
37     shave(4);
38     //~^ ERROR: unresolved name `shave`. Did you mean to call `Groom::shave`?
39     purr();
40     //~^ ERROR: unresolved name `purr`
41   }
42 }
43
44 impl cat {
45     fn static_method() {}
46
47     fn purr_louder() {
48         static_method();
49         //~^ ERROR: unresolved name `static_method`
50         purr();
51         //~^ ERROR: unresolved name `purr`
52         purr();
53         //~^ ERROR: unresolved name `purr`
54         purr();
55         //~^ ERROR: unresolved name `purr`
56     }
57 }
58
59 impl cat {
60   fn meow() {
61     if self.whiskers > 3 {
62         //~^ ERROR `self` is not available in a static method [E0424]
63         //~| NOTE not available in static method
64         //~| NOTE maybe a `self` argument is missing?
65         println!("MEOW");
66     }
67   }
68
69   fn purr(&self) {
70     grow_older();
71     //~^ ERROR: unresolved name `grow_older`
72     shave();
73     //~^ ERROR: unresolved name `shave`
74   }
75
76   fn burn_whiskers(&mut self) {
77     whiskers = 0;
78     //~^ ERROR: unresolved name `whiskers`. Did you mean `self.whiskers`?
79   }
80
81   pub fn grow_older(other:usize) {
82     whiskers = 4;
83     //~^ ERROR: unresolved name `whiskers`
84     //~| HELP this is an associated function
85     purr_louder();
86     //~^ ERROR: unresolved name `purr_louder`
87   }
88 }
89
90 fn main() {
91     self += 1;
92     //~^ ERROR: unresolved name `self`
93     //~| HELP: module `self`
94     // it's a bug if this suggests a missing `self` as we're not in a method
95 }