]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/unsized2.rs
Make RFC 1214 warnings into errors, and rip out the "warn or err"
[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 #![allow(unknown_features)]
12 #![feature(box_syntax)]
13
14 // Test sized-ness checking in substitution.
15
16 use std::marker;
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 { fn dummy(&self) { } }
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 dummy(&self) { }
70     fn m1(&self, x: &T4<X>, y: X);
71     fn m2(&self, x: &T5<X>, y: X);
72 }
73 trait T5<X: ?Sized> {
74     fn dummy(&self) { }
75     // not an error (for now)
76     fn m1(&self, x: &T4<X>);
77     fn m2(&self, x: &T5<X>);
78 }
79
80 trait T6<X: T> {
81     fn dummy(&self) { }
82     fn m1(&self, x: &T4<X>);
83     fn m2(&self, x: &T5<X>);
84 }
85 trait T7<X: ?Sized+T> {
86     fn dummy(&self) { }
87     // not an error (for now)
88     fn m1(&self, x: &T4<X>);
89     fn m2(&self, x: &T5<X>);
90 }
91
92 // The last field in a struct or variant may be unsized
93 struct S2<X: ?Sized> {
94     f: X,
95 }
96 struct S3<X: ?Sized> {
97     f1: isize,
98     f2: X,
99 }
100 enum E<X: ?Sized> {
101     V1(X),
102     V2{x: X},
103     V3(isize, X),
104     V4{u: isize, x: X},
105 }
106
107 pub fn main() {
108 }