]>
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 | // Make sure rustc checks the type parameter bounds in implementations of traits, | |
12 | // see #2687 | |
13 | ||
85aaf69f SL |
14 | use std::marker; |
15 | ||
9346a6ac | 16 | trait A { } |
1a4d82fc JJ |
17 | |
18 | trait B: A {} | |
19 | ||
20 | trait C: A {} | |
21 | ||
22 | trait Foo { | |
23 | fn test_error1_fn<T: Eq>(&self); | |
24 | fn test_error2_fn<T: Eq + Ord>(&self); | |
25 | fn test_error3_fn<T: Eq + Ord>(&self); | |
26 | fn test3_fn<T: Eq + Ord>(&self); | |
27 | fn test4_fn<T: Eq + Ord>(&self); | |
28 | fn test_error5_fn<T: A>(&self); | |
29 | fn test6_fn<T: A + Eq>(&self); | |
30 | fn test_error7_fn<T: A>(&self); | |
31 | fn test_error8_fn<T: B>(&self); | |
32 | } | |
33 | ||
34 | impl Foo for isize { | |
35 | // invalid bound for T, was defined as Eq in trait | |
36 | fn test_error1_fn<T: Ord>(&self) {} | |
54a0048b | 37 | //~^ ERROR the requirement `T: std::cmp::Ord` appears on the impl |
1a4d82fc JJ |
38 | |
39 | // invalid bound for T, was defined as Eq + Ord in trait | |
40 | fn test_error2_fn<T: Eq + B>(&self) {} | |
54a0048b | 41 | //~^ ERROR the requirement `T: B` appears on the impl |
1a4d82fc JJ |
42 | |
43 | // invalid bound for T, was defined as Eq + Ord in trait | |
44 | fn test_error3_fn<T: B + Eq>(&self) {} | |
54a0048b | 45 | //~^ ERROR the requirement `T: B` appears on the impl |
1a4d82fc JJ |
46 | |
47 | // multiple bounds, same order as in trait | |
48 | fn test3_fn<T: Ord + Eq>(&self) {} | |
49 | ||
50 | // multiple bounds, different order as in trait | |
51 | fn test4_fn<T: Eq + Ord>(&self) {} | |
52 | ||
53 | // parameters in impls must be equal or more general than in the defining trait | |
54 | fn test_error5_fn<T: B>(&self) {} | |
54a0048b | 55 | //~^ ERROR the requirement `T: B` appears on the impl |
1a4d82fc JJ |
56 | |
57 | // bound `std::cmp::Eq` not enforced by this implementation, but this is OK | |
58 | fn test6_fn<T: A>(&self) {} | |
59 | ||
60 | fn test_error7_fn<T: A + Eq>(&self) {} | |
54a0048b | 61 | //~^ ERROR the requirement `T: std::cmp::Eq` appears on the impl |
1a4d82fc JJ |
62 | |
63 | fn test_error8_fn<T: C>(&self) {} | |
54a0048b | 64 | //~^ ERROR the requirement `T: C` appears on the impl |
1a4d82fc JJ |
65 | } |
66 | ||
85aaf69f SL |
67 | trait Getter<T> { |
68 | fn get(&self) -> T { loop { } } | |
69 | } | |
1a4d82fc JJ |
70 | |
71 | trait Trait { | |
85aaf69f | 72 | fn method<G:Getter<isize>>(&self); |
1a4d82fc JJ |
73 | } |
74 | ||
75 | impl Trait for usize { | |
85aaf69f SL |
76 | fn method<G: Getter<usize>>(&self) {} |
77 | //~^ G : Getter<usize>` appears on the impl method but not on the corresponding trait method | |
1a4d82fc JJ |
78 | } |
79 | ||
80 | fn main() {} |