2018-08-30 12:18:55 +00:00
|
|
|
//@ run-pass
|
2018-09-25 21:51:35 +00:00
|
|
|
#![allow(dead_code)]
|
2012-11-28 20:34:30 +00:00
|
|
|
// Testing that this impl turns A into a Quux, because
|
|
|
|
// A is already a Foo Bar Baz
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2013-02-21 01:07:17 +00:00
|
|
|
impl<T:Foo + Bar + Baz> Quux for T { }
|
2012-11-28 20:34:30 +00:00
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
trait Foo { fn f(&self) -> isize; }
|
|
|
|
trait Bar { fn g(&self) -> isize; }
|
|
|
|
trait Baz { fn h(&self) -> isize; }
|
2012-11-28 20:34:30 +00:00
|
|
|
|
2013-03-05 00:11:30 +00:00
|
|
|
trait Quux: Foo + Bar + Baz { }
|
2012-11-28 20:34:30 +00:00
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
struct A { x: isize }
|
2012-11-28 20:34:30 +00:00
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
impl Foo for A { fn f(&self) -> isize { 10 } }
|
|
|
|
impl Bar for A { fn g(&self) -> isize { 20 } }
|
|
|
|
impl Baz for A { fn h(&self) -> isize { 30 } }
|
2012-11-28 20:34:30 +00:00
|
|
|
|
2013-02-21 01:07:17 +00:00
|
|
|
fn f<T:Quux>(a: &T) {
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(a.f(), 10);
|
|
|
|
assert_eq!(a.g(), 20);
|
|
|
|
assert_eq!(a.h(), 30);
|
2012-11-28 20:34:30 +00:00
|
|
|
}
|
|
|
|
|
2013-02-02 03:43:17 +00:00
|
|
|
pub fn main() {
|
2012-11-28 20:34:30 +00:00
|
|
|
let a = &A { x: 3 };
|
|
|
|
f(a);
|
|
|
|
}
|