Graydon Hoare | d1affff | 2012-12-11 01:32:48 | [diff] [blame] | 1 | // Copyright 2012 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 | |
Brian Anderson | 78ee821 | 2012-11-28 20:34:30 | [diff] [blame] | 11 | // B and C both require A, so D does as well, twice, but that's just fine |
| 12 | |
| 13 | trait A { fn a(&self) -> int; } |
| 14 | trait B: A { fn b(&self) -> int; } |
| 15 | trait C: A { fn c(&self) -> int; } |
Patrick Walton | 6d4ed52 | 2013-03-05 00:11:30 | [diff] [blame] | 16 | trait D: B + C { fn d(&self) -> int; } |
Brian Anderson | 78ee821 | 2012-11-28 20:34:30 | [diff] [blame] | 17 | |
| 18 | struct S { bogus: () } |
| 19 | |
Patrick Walton | 9143688 | 2013-02-14 19:47:00 | [diff] [blame] | 20 | impl A for S { fn a(&self) -> int { 10 } } |
| 21 | impl B for S { fn b(&self) -> int { 20 } } |
| 22 | impl C for S { fn c(&self) -> int { 30 } } |
| 23 | impl D for S { fn d(&self) -> int { 40 } } |
Brian Anderson | 78ee821 | 2012-11-28 20:34:30 | [diff] [blame] | 24 | |
Patrick Walton | bf2a225 | 2013-02-21 01:07:17 | [diff] [blame] | 25 | fn f<T:D>(x: &T) { |
Corey Richardson | cc57ca0 | 2013-05-19 02:02:45 | [diff] [blame] | 26 | assert_eq!(x.a(), 10); |
| 27 | assert_eq!(x.b(), 20); |
| 28 | assert_eq!(x.c(), 30); |
| 29 | assert_eq!(x.d(), 40); |
Brian Anderson | 78ee821 | 2012-11-28 20:34:30 | [diff] [blame] | 30 | } |
| 31 | |
Graydon Hoare | 89c8ef7 | 2013-02-02 03:43:17 | [diff] [blame] | 32 | pub fn main() { |
Brian Anderson | 78ee821 | 2012-11-28 20:34:30 | [diff] [blame] | 33 | let value = &S { bogus: () }; |
| 34 | f(value); |
Patrick Walton | 9143688 | 2013-02-14 19:47:00 | [diff] [blame] | 35 | } |