]> git.lizzy.rs Git - rust.git/blob - src/test/ui/associated-types/associated-types-return.rs
feat(rustdoc): open sidebar menu when links inside it are focused
[rust.git] / src / test / ui / associated-types / associated-types-return.rs
1 // run-pass
2 // Test equality constraints on associated types in a where clause.
3
4
5 pub trait Foo {
6     type A;
7     fn boo(&self) -> <Self as Foo>::A;
8 }
9
10 #[derive(PartialEq, Debug)]
11 pub struct Bar;
12
13 impl Foo for isize {
14     type A = usize;
15     fn boo(&self) -> usize { 42 }
16 }
17
18 impl Foo for Bar {
19     type A = isize;
20     fn boo(&self) -> isize { 43 }
21 }
22
23 impl Foo for char {
24     type A = Bar;
25     fn boo(&self) -> Bar { Bar }
26 }
27
28 fn foo1<I: Foo<A=Bar>>(x: I) -> Bar {
29     x.boo()
30 }
31
32 fn foo2<I: Foo>(x: I) -> <I as Foo>::A {
33     x.boo()
34 }
35
36 pub fn main() {
37     let a = 42;
38     assert_eq!(foo2(a), 42);
39
40     let a = Bar;
41     assert_eq!(foo2(a), 43);
42
43     let a = 'a';
44     foo1(a);
45     assert_eq!(foo2(a), Bar);
46 }