]> git.proxmox.com Git - rustc.git/blob - src/test/ui/compare-method/traits-misc-mismatch-1.rs
New upstream version 1.14.0+dfsg1
[rustc.git] / src / test / ui / compare-method / traits-misc-mismatch-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 use std::marker;
15
16 trait A { }
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) {}
37 //~^ ERROR E0276
38
39 // invalid bound for T, was defined as Eq + Ord in trait
40 fn test_error2_fn<T: Eq + B>(&self) {}
41 //~^ ERROR E0276
42
43 // invalid bound for T, was defined as Eq + Ord in trait
44 fn test_error3_fn<T: B + Eq>(&self) {}
45 //~^ ERROR E0276
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) {}
55 //~^ ERROR E0276
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) {}
61 //~^ ERROR E0276
62
63 fn test_error8_fn<T: C>(&self) {}
64 //~^ ERROR E0276
65 }
66
67 trait Getter<T> {
68 fn get(&self) -> T { loop { } }
69 }
70
71 trait Trait {
72 fn method<G:Getter<isize>>(&self);
73 }
74
75 impl Trait for usize {
76 fn method<G: Getter<usize>>(&self) {}
77 //~^ ERROR E0276
78 }
79
80 fn main() {}