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