]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/issue-7575.rs
Fix misspelled comments.
[rust.git] / src / test / compile-fail / issue-7575.rs
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
13 trait CtxtFn {
14     fn f8(self, uint) -> uint;
15     fn f9(uint) -> uint; //~ NOTE candidate
16 }
17
18 trait OtherTrait {
19     fn f9(uint) -> uint; //~ NOTE candidate
20 }
21
22 // Note: this trait is not implemented, but we can't really tell
23 // whether or not an impl would match anyhow without a self
24 // declaration to match against, so we wind up printing it as a
25 // candidate. This seems not unreasonable -- perhaps the user meant to
26 // implement it, after all.
27 trait UnusedTrait {
28     fn f9(uint) -> uint; //~ NOTE candidate
29 }
30
31 impl CtxtFn for uint {
32     fn f8(self, i: uint) -> uint {
33         i * 4u
34     }
35
36     fn f9(i: uint) -> uint {
37         i * 4u
38     }
39 }
40
41 impl OtherTrait for uint {
42     fn f9(i: uint) -> uint {
43         i * 8u
44     }
45 }
46
47 struct MyInt(int);
48
49 impl MyInt {
50     fn fff(i: int) -> int { //~ NOTE candidate
51         i
52     }
53 }
54
55 trait ManyImplTrait {
56     fn is_str() -> bool { //~ NOTE candidate
57         false
58     }
59 }
60
61 impl ManyImplTrait for String {
62     fn is_str() -> bool {
63         true
64     }
65 }
66
67 impl ManyImplTrait for uint {}
68 impl ManyImplTrait for int {}
69 impl ManyImplTrait for char {}
70 impl ManyImplTrait for MyInt {}
71
72 fn no_param_bound(u: uint, m: MyInt) -> uint {
73     u.f8(42) + u.f9(342) + m.fff(42)
74             //~^ ERROR type `uint` does not implement any method in scope named `f9`
75             //~^^ NOTE found defined static methods, maybe a `self` is missing?
76                         //~^^^ ERROR type `MyInt` does not implement any method in scope named `fff`
77                         //~^^^^ NOTE found defined static methods, maybe a `self` is missing?
78 }
79
80 fn param_bound<T: ManyImplTrait>(t: T) -> bool {
81     t.is_str()
82     //~^ ERROR type `T` does not implement any method in scope named `is_str`
83     //~^^ NOTE found defined static methods, maybe a `self` is missing?
84 }
85
86 fn main() {
87 }