blob: 253c10ac6f1b037196c2d4980f20d9f3ed5123cc [file] [log] [blame]
Graydon Hoared1affff2012-12-11 01:32:481// 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 Anderson78ee8212012-11-28 20:34:3011// B and C both require A, so D does as well, twice, but that's just fine
12
13trait A { fn a(&self) -> int; }
14trait B: A { fn b(&self) -> int; }
15trait C: A { fn c(&self) -> int; }
Patrick Walton6d4ed522013-03-05 00:11:3016trait D: B + C { fn d(&self) -> int; }
Brian Anderson78ee8212012-11-28 20:34:3017
18struct S { bogus: () }
19
Patrick Walton91436882013-02-14 19:47:0020impl A for S { fn a(&self) -> int { 10 } }
21impl B for S { fn b(&self) -> int { 20 } }
22impl C for S { fn c(&self) -> int { 30 } }
23impl D for S { fn d(&self) -> int { 40 } }
Brian Anderson78ee8212012-11-28 20:34:3024
Patrick Waltonbf2a2252013-02-21 01:07:1725fn f<T:D>(x: &T) {
Corey Richardsoncc57ca02013-05-19 02:02:4526 assert_eq!(x.a(), 10);
27 assert_eq!(x.b(), 20);
28 assert_eq!(x.c(), 30);
29 assert_eq!(x.d(), 40);
Brian Anderson78ee8212012-11-28 20:34:3030}
31
Graydon Hoare89c8ef72013-02-02 03:43:1732pub fn main() {
Brian Anderson78ee8212012-11-28 20:34:3033 let value = &S { bogus: () };
34 f(value);
Patrick Walton91436882013-02-14 19:47:0035}