]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/issue-2356.rs
Auto merge of #33816 - nikomatsakis:projection-cache-2, r=arielb1
[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. Maybe a `self` argument is missing?
63         println!("MEOW");
64     }
65   }
66
67   fn purr(&self) {
68     grow_older();
69     //~^ ERROR: unresolved name `grow_older`
70     shave();
71     //~^ ERROR: unresolved name `shave`
72   }
73
74   fn burn_whiskers(&mut self) {
75     whiskers = 0;
76     //~^ ERROR: unresolved name `whiskers`. Did you mean `self.whiskers`?
77   }
78
79   pub fn grow_older(other:usize) {
80     whiskers = 4;
81     //~^ ERROR: unresolved name `whiskers`
82     //~| HELP this is an associated function
83     purr_louder();
84     //~^ ERROR: unresolved name `purr_louder`
85   }
86 }
87
88 fn main() {
89     self += 1;
90     //~^ ERROR: unresolved name `self`
91     //~| HELP: module `self`
92     // it's a bug if this suggests a missing `self` as we're not in a method
93 }