]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/associated-types-return.rs
rustdoc: Replace no-pretty-expanded with pretty-expanded
[rust.git] / src / test / run-pass / associated-types-return.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 equality constraints on associated types in a where clause.
12
13 // pretty-expanded FIXME #23616
14
15 pub trait Foo {
16     type A;
17     fn boo(&self) -> <Self as Foo>::A;
18 }
19
20 #[derive(PartialEq)]
21 pub struct Bar;
22
23 impl Foo for int {
24     type A = uint;
25     fn boo(&self) -> uint { 42 }
26 }
27
28 impl Foo for Bar {
29     type A = int;
30     fn boo(&self) -> int { 43 }
31 }
32
33 impl Foo for char {
34     type A = Bar;
35     fn boo(&self) -> Bar { Bar }
36 }
37
38 fn foo1<I: Foo<A=Bar>>(x: I) -> Bar {
39     x.boo()
40 }
41
42 fn foo2<I: Foo>(x: I) -> <I as Foo>::A {
43     x.boo()
44 }
45
46 pub fn main() {
47     let a = 42;
48     assert!(foo2(a) == 42);
49
50     let a = Bar;
51     assert!(foo2(a) == 43);
52
53     let a = 'a';
54     foo1(a);
55     assert!(foo2(a) == Bar);
56 }