2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2013-10-23 04:04:15 +00:00
|
|
|
// Tests that everything still compiles and runs fine even when
|
|
|
|
// we reorder the bounds.
|
|
|
|
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2013-10-23 04:04:15 +00:00
|
|
|
trait A {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn a(&self) -> usize;
|
2013-10-23 04:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
trait B {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn b(&self) -> usize;
|
2013-10-23 04:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
trait C {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn combine<T:A+B>(&self, t: &T) -> usize;
|
2013-10-23 04:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Foo;
|
|
|
|
|
|
|
|
impl A for Foo {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn a(&self) -> usize { 1 }
|
2013-10-23 04:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl B for Foo {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn b(&self) -> usize { 2 }
|
2013-10-23 04:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Bar;
|
|
|
|
|
|
|
|
impl C for Bar {
|
|
|
|
// Note below: bounds in impl decl are in reverse order.
|
2015-03-26 00:06:52 +00:00
|
|
|
fn combine<T:B+A>(&self, t: &T) -> usize {
|
2013-10-23 04:04:15 +00:00
|
|
|
(t.a() * 100) + t.b()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn use_c<S:C, T:B+A>(s: &S, t: &T) -> usize {
|
2013-10-23 04:04:15 +00:00
|
|
|
s.combine(t)
|
|
|
|
}
|
|
|
|
|
2014-01-03 23:30:54 +00:00
|
|
|
pub fn main() {
|
2013-10-23 04:04:15 +00:00
|
|
|
let foo = Foo;
|
|
|
|
let bar = Bar;
|
|
|
|
let r = use_c(&bar, &foo);
|
|
|
|
assert_eq!(r, 102);
|
|
|
|
}
|