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