]> git.lizzy.rs Git - rust.git/blob - src/test/ui/self/self-impl-2.rs
Update ui tests
[rust.git] / src / test / ui / self / self-impl-2.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![allow(unused_variables)]
4 // Test that we can use `Self` types in impls in the expected way.
5
6 // pretty-expanded FIXME #23616
7
8 #![feature(box_syntax)]
9
10 struct Foo;
11
12 // Test uses on inherent impl.
13 impl Foo {
14     fn foo(_x: Self, _y: &Self, _z: Box<Self>) -> Self {
15         Foo
16     }
17
18     fn baz() {
19         // Test that Self cannot be shadowed.
20         type Foo = i32;
21         // There is no empty method on i32.
22         Self::empty();
23
24         let _: Self = Foo;
25     }
26
27     fn empty() {}
28 }
29
30 // Test uses when implementing a trait and with a type parameter.
31 pub struct Baz<X> {
32     pub f: X,
33 }
34
35 trait SuperBar {
36     type SuperQux;
37 }
38
39 trait Bar<X>: SuperBar {
40     type Qux;
41
42     fn bar(x: Self, y: &Self, z: Box<Self>, _: Self::SuperQux) -> Self;
43     fn dummy(&self, x: X) { }
44 }
45
46 impl SuperBar for Box<Baz<isize>> {
47     type SuperQux = bool;
48 }
49
50 impl Bar<isize> for Box<Baz<isize>> {
51     type Qux = i32;
52
53     fn bar(_x: Self, _y: &Self, _z: Box<Self>, _: Self::SuperQux) -> Self {
54         let _: Self::Qux = 42;
55         let _: <Self as Bar<isize>>::Qux = 42;
56
57         let _: Self::SuperQux = true;
58         let _: <Self as SuperBar>::SuperQux = true;
59
60         box Baz { f: 42 }
61     }
62 }
63
64 fn main() {
65     let _: Foo = Foo::foo(Foo, &Foo, box Foo);
66     let _: Box<Baz<isize>> = Bar::bar(box Baz { f: 42 },
67                                       &box Baz { f: 42 },
68                                       box box Baz { f: 42 },
69                                       true);
70 }