]> git.lizzy.rs Git - rust.git/blob - src/test/ui/unsized2.rs
Merge commit '9a0c32934ebe376128230aa8da3275697b2053e7' into sync_cg_clif-2021-03-05
[rust.git] / src / test / ui / unsized2.rs
1 // run-pass
2
3 #![allow(unconditional_recursion)]
4 #![allow(dead_code)]
5 #![allow(unused_variables)]
6 #![allow(unused_imports)]
7 #![feature(box_syntax)]
8
9 // Test sized-ness checking in substitution.
10
11 use std::marker;
12
13 // Unbounded.
14 fn f1<X: ?Sized>(x: &X) {
15     f1::<X>(x);
16 }
17 fn f2<X>(x: &X) {
18     f1::<X>(x);
19     f2::<X>(x);
20 }
21
22 // Bounded.
23 trait T { fn dummy(&self) { } }
24 fn f3<X: T+?Sized>(x: &X) {
25     f3::<X>(x);
26 }
27 fn f4<X: T>(x: &X) {
28     f3::<X>(x);
29     f4::<X>(x);
30 }
31
32 // Self type.
33 trait T2 {
34     fn f() -> Box<Self>;
35 }
36 struct S;
37 impl T2 for S {
38     fn f() -> Box<S> {
39         box S
40     }
41 }
42 fn f5<X: ?Sized+T2>(x: &X) {
43     let _: Box<X> = T2::f();
44 }
45 fn f6<X: T2>(x: &X) {
46     let _: Box<X> = T2::f();
47 }
48
49 trait T3 {
50     fn f() -> Box<Self>;
51 }
52 impl T3 for S {
53     fn f() -> Box<S> {
54         box S
55     }
56 }
57 fn f7<X: ?Sized+T3>(x: &X) {
58     // This is valid, but the unsized bound on X is irrelevant because any type
59     // which implements T3 must have statically known size.
60     let _: Box<X> = T3::f();
61 }
62
63 trait T4<X> {
64     fn dummy(&self) { }
65     fn m1(&self, x: &dyn T4<X>, y: X);
66     fn m2(&self, x: &dyn T5<X>, y: X);
67 }
68 trait T5<X: ?Sized> {
69     fn dummy(&self) { }
70     // not an error (for now)
71     fn m1(&self, x: &dyn T4<X>);
72     fn m2(&self, x: &dyn T5<X>);
73 }
74
75 trait T6<X: T> {
76     fn dummy(&self) { }
77     fn m1(&self, x: &dyn T4<X>);
78     fn m2(&self, x: &dyn T5<X>);
79 }
80 trait T7<X: ?Sized+T> {
81     fn dummy(&self) { }
82     // not an error (for now)
83     fn m1(&self, x: &dyn T4<X>);
84     fn m2(&self, x: &dyn T5<X>);
85 }
86
87 // The last field in a struct may be unsized
88 struct S2<X: ?Sized> {
89     f: X,
90 }
91 struct S3<X: ?Sized> {
92     f1: isize,
93     f2: X,
94 }
95
96 pub fn main() {
97 }