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