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