]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/associated-types-sugar-path.rs
Auto merge of #22541 - Manishearth:rollup, r=Gankro
[rust.git] / src / test / run-pass / associated-types-sugar-path.rs
1 // Copyright 2014 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
11 // Test paths to associated types using the type-parameter-only sugar.
12
13 pub trait Foo {
14     type A;
15     fn boo(&self) -> Self::A;
16 }
17
18 impl Foo for int {
19     type A = uint;
20     fn boo(&self) -> uint {
21         5
22     }
23 }
24
25 // Using a type via a function.
26 pub fn bar<T: Foo>(a: T, x: T::A) -> T::A {
27     let _: T::A = a.boo();
28     x
29 }
30
31 // Using a type via an impl.
32 trait C {
33     fn f();
34     fn g(&self) { }
35 }
36 struct B<X>(X);
37 impl<T: Foo> C for B<T> {
38     fn f() {
39         let x: T::A = panic!();
40     }
41 }
42
43 pub fn main() {
44     let z: uint = bar(2, 4_usize);
45 }