]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
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 | // Test the mechanism for warning about possible missing `self` declarations. | |
12 | ||
85aaf69f SL |
13 | use std::marker::MarkerTrait; |
14 | ||
1a4d82fc JJ |
15 | trait CtxtFn { |
16 | fn f8(self, usize) -> usize; | |
17 | fn f9(usize) -> usize; //~ NOTE candidate | |
18 | } | |
19 | ||
85aaf69f | 20 | trait OtherTrait : MarkerTrait { |
1a4d82fc JJ |
21 | fn f9(usize) -> usize; //~ NOTE candidate |
22 | } | |
23 | ||
24 | // Note: this trait is not implemented, but we can't really tell | |
25 | // whether or not an impl would match anyhow without a self | |
26 | // declaration to match against, so we wind up prisizeing it as a | |
27 | // candidate. This seems not unreasonable -- perhaps the user meant to | |
28 | // implement it, after all. | |
85aaf69f | 29 | trait UnusedTrait : MarkerTrait { |
1a4d82fc JJ |
30 | fn f9(usize) -> usize; //~ NOTE candidate |
31 | } | |
32 | ||
33 | impl CtxtFn for usize { | |
34 | fn f8(self, i: usize) -> usize { | |
c34b1796 | 35 | i * 4 |
1a4d82fc JJ |
36 | } |
37 | ||
38 | fn f9(i: usize) -> usize { | |
c34b1796 | 39 | i * 4 |
1a4d82fc JJ |
40 | } |
41 | } | |
42 | ||
43 | impl OtherTrait for usize { | |
44 | fn f9(i: usize) -> usize { | |
c34b1796 | 45 | i * 8 |
1a4d82fc JJ |
46 | } |
47 | } | |
48 | ||
49 | struct Myisize(isize); | |
50 | ||
51 | impl Myisize { | |
52 | fn fff(i: isize) -> isize { //~ NOTE candidate | |
53 | i | |
54 | } | |
55 | } | |
56 | ||
85aaf69f | 57 | trait ManyImplTrait : MarkerTrait { |
1a4d82fc JJ |
58 | fn is_str() -> bool { //~ NOTE candidate |
59 | false | |
60 | } | |
61 | } | |
62 | ||
63 | impl ManyImplTrait for String { | |
64 | fn is_str() -> bool { | |
65 | true | |
66 | } | |
67 | } | |
68 | ||
69 | impl ManyImplTrait for usize {} | |
70 | impl ManyImplTrait for isize {} | |
71 | impl ManyImplTrait for char {} | |
72 | impl ManyImplTrait for Myisize {} | |
73 | ||
74 | fn no_param_bound(u: usize, m: Myisize) -> usize { | |
75 | u.f8(42) + u.f9(342) + m.fff(42) | |
76 | //~^ ERROR type `usize` does not implement any method in scope named `f9` | |
77 | //~^^ NOTE found defined static methods, maybe a `self` is missing? | |
78 | //~^^^ ERROR type `Myisize` does not implement any method in scope named `fff` | |
79 | //~^^^^ NOTE found defined static methods, maybe a `self` is missing? | |
80 | } | |
81 | ||
82 | fn param_bound<T: ManyImplTrait>(t: T) -> bool { | |
83 | t.is_str() | |
84 | //~^ ERROR type `T` does not implement any method in scope named `is_str` | |
85 | //~^^ NOTE found defined static methods, maybe a `self` is missing? | |
86 | } | |
87 | ||
88 | fn main() { | |
89 | } |