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