summaryrefslogtreecommitdiffstats
path: root/tests/ui/unsized/unsized2.rs
blob: bbeb00d5fed60c423cb0fc371710193f6f97d31c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// run-pass

#![allow(unconditional_recursion)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_imports)]

// Test sized-ness checking in substitution.

use std::marker;

// Unbounded.
fn f1<X: ?Sized>(x: &X) {
    f1::<X>(x);
}
fn f2<X>(x: &X) {
    f1::<X>(x);
    f2::<X>(x);
}

// Bounded.
trait T { fn dummy(&self) { } }
fn f3<X: T+?Sized>(x: &X) {
    f3::<X>(x);
}
fn f4<X: T>(x: &X) {
    f3::<X>(x);
    f4::<X>(x);
}

// Self type.
trait T2 {
    fn f() -> Box<Self>;
}
struct S;
impl T2 for S {
    fn f() -> Box<S> {
        Box::new(S)
    }
}
fn f5<X: ?Sized+T2>(x: &X) {
    let _: Box<X> = T2::f();
}
fn f6<X: T2>(x: &X) {
    let _: Box<X> = T2::f();
}

trait T3 {
    fn f() -> Box<Self>;
}
impl T3 for S {
    fn f() -> Box<S> {
        Box::new(S)
    }
}
fn f7<X: ?Sized+T3>(x: &X) {
    // This is valid, but the unsized bound on X is irrelevant because any type
    // which implements T3 must have statically known size.
    let _: Box<X> = T3::f();
}

trait T4<X> {
    fn dummy(&self) { }
    fn m1(&self, x: &dyn T4<X>, y: X);
    fn m2(&self, x: &dyn T5<X>, y: X);
}
trait T5<X: ?Sized> {
    fn dummy(&self) { }
    // not an error (for now)
    fn m1(&self, x: &dyn T4<X>);
    fn m2(&self, x: &dyn T5<X>);
}

trait T6<X: T> {
    fn dummy(&self) { }
    fn m1(&self, x: &dyn T4<X>);
    fn m2(&self, x: &dyn T5<X>);
}
trait T7<X: ?Sized+T> {
    fn dummy(&self) { }
    // not an error (for now)
    fn m1(&self, x: &dyn T4<X>);
    fn m2(&self, x: &dyn T5<X>);
}

// The last field in a struct may be unsized
struct S2<X: ?Sized> {
    f: X,
}
struct S3<X: ?Sized> {
    f1: isize,
    f2: X,
}

pub fn main() {
}