]> git.lizzy.rs Git - rust.git/blob - src/test/ui/compare-method/traits-misc-mismatch-1.rs
Rollup merge of #106248 - dtolnay:revertupcastlint, r=jackh726
[rust.git] / src / test / ui / compare-method / traits-misc-mismatch-1.rs
1 //
2 // Make sure rustc checks the type parameter bounds in implementations of traits,
3 // see #2687
4
5 use std::marker;
6
7 trait A { }
8
9 trait B: A {}
10
11 trait C: A {}
12
13 trait Foo {
14     fn test_error1_fn<T: Eq>(&self);
15     fn test_error2_fn<T: Eq + Ord>(&self);
16     fn test_error3_fn<T: Eq + Ord>(&self);
17     fn test3_fn<T: Eq + Ord>(&self);
18     fn test4_fn<T: Eq + Ord>(&self);
19     fn test_error5_fn<T: A>(&self);
20     fn test6_fn<T: A + Eq>(&self);
21     fn test_error7_fn<T: A>(&self);
22     fn test_error8_fn<T: B>(&self);
23 }
24
25 impl Foo for isize {
26     // invalid bound for T, was defined as Eq in trait
27     fn test_error1_fn<T: Ord>(&self) {}
28     //~^ ERROR E0276
29
30     // invalid bound for T, was defined as Eq + Ord in trait
31     fn test_error2_fn<T: Eq + B>(&self) {}
32     //~^ ERROR E0276
33
34     // invalid bound for T, was defined as Eq + Ord in trait
35     fn test_error3_fn<T: B + Eq>(&self) {}
36     //~^ ERROR E0276
37
38     // multiple bounds, same order as in trait
39     fn test3_fn<T: Ord + Eq>(&self) {}
40
41     // multiple bounds, different order as in trait
42     fn test4_fn<T: Eq + Ord>(&self) {}
43
44     // parameters in impls must be equal or more general than in the defining trait
45     fn test_error5_fn<T: B>(&self) {}
46     //~^ ERROR E0276
47
48     // bound `std::cmp::Eq` not enforced by this implementation, but this is OK
49     fn test6_fn<T: A>(&self) {}
50
51     fn test_error7_fn<T: A + Eq>(&self) {}
52     //~^ ERROR E0276
53
54     fn test_error8_fn<T: C>(&self) {}
55     //~^ ERROR E0276
56 }
57
58 trait Getter<T> {
59     fn get(&self) -> T { loop { } }
60 }
61
62 trait Trait {
63     fn method<G:Getter<isize>>(&self);
64 }
65
66 impl Trait for usize {
67     fn method<G: Getter<usize>>(&self) {}
68     //~^ ERROR E0276
69 }
70
71 fn main() {}