]> git.proxmox.com Git - rustc.git/blob - src/test/ui/traits/issue-6334.rs
New upstream version 1.51.0+dfsg1
[rustc.git] / src / test / ui / traits / issue-6334.rs
1 // run-pass
2 // Tests that everything still compiles and runs fine even when
3 // we reorder the bounds.
4
5
6 trait A {
7 fn a(&self) -> usize;
8 }
9
10 trait B {
11 fn b(&self) -> usize;
12 }
13
14 trait C {
15 fn combine<T:A+B>(&self, t: &T) -> usize;
16 }
17
18 struct Foo;
19
20 impl A for Foo {
21 fn a(&self) -> usize { 1 }
22 }
23
24 impl B for Foo {
25 fn b(&self) -> usize { 2 }
26 }
27
28 struct Bar;
29
30 impl C for Bar {
31 // Note below: bounds in impl decl are in reverse order.
32 fn combine<T:B+A>(&self, t: &T) -> usize {
33 (t.a() * 100) + t.b()
34 }
35 }
36
37 fn use_c<S:C, T:B+A>(s: &S, t: &T) -> usize {
38 s.combine(t)
39 }
40
41 pub fn main() {
42 let foo = Foo;
43 let bar = Bar;
44 let r = use_c(&bar, &foo);
45 assert_eq!(r, 102);
46 }