]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/unsized2.rs
auto merge of #20154 : P1start/rust/qualified-assoc-type-generics, r=nikomatsakis
[rust.git] / src / test / run-pass / unsized2.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 // ignore-lexer-test FIXME #15879
12
13 // Test sized-ness checking in substitution.
14
15 // Unbounded.
16 fn f1<X: ?Sized>(x: &X) {
17     f1::<X>(x);
18 }
19 fn f2<X>(x: &X) {
20     f1::<X>(x);
21     f2::<X>(x);
22 }
23
24 // Bounded.
25 trait T for ?Sized {}
26 fn f3<X: T+?Sized>(x: &X) {
27     f3::<X>(x);
28 }
29 fn f4<X: T>(x: &X) {
30     f3::<X>(x);
31     f4::<X>(x);
32 }
33
34 // Self type.
35 trait T2 for ?Sized {
36     fn f() -> Box<Self>;
37 }
38 struct S;
39 impl T2 for S {
40     fn f() -> Box<S> {
41         box S
42     }
43 }
44 fn f5<X: ?Sized+T2>(x: &X) {
45     let _: Box<X> = T2::f();
46 }
47 fn f6<X: T2>(x: &X) {
48     let _: Box<X> = T2::f();
49 }
50
51 trait T3 for ?Sized {
52     fn f() -> Box<Self>;
53 }
54 impl T3 for S {
55     fn f() -> Box<S> {
56         box S
57     }
58 }
59 fn f7<X: ?Sized+T3>(x: &X) {
60     // This is valid, but the unsized bound on X is irrelevant because any type
61     // which implements T3 must have statically known size.
62     let _: Box<X> = T3::f();
63 }
64
65 trait T4<X> {
66     fn m1(x: &T4<X>);
67     fn m2(x: &T5<X>);
68 }
69 trait T5<X: ?Sized> {
70     // not an error (for now)
71     fn m1(x: &T4<X>);
72     fn m2(x: &T5<X>);
73 }
74
75 trait T6<X: T> {
76     fn m1(x: &T4<X>);
77     fn m2(x: &T5<X>);
78 }
79 trait T7<X: ?Sized+T> {
80     // not an error (for now)
81     fn m1(x: &T4<X>);
82     fn m2(x: &T5<X>);
83 }
84
85 // The last field in a struct or variant may be unsized
86 struct S2<X: ?Sized> {
87     f: X,
88 }
89 struct S3<X: ?Sized> {
90     f1: int,
91     f2: X,
92 }
93 enum E<X: ?Sized> {
94     V1(X),
95     V2{x: X},
96     V3(int, X),
97     V4{u: int, x: X},
98 }
99
100 pub fn main() {
101 }