summaryrefslogtreecommitdiffstats
path: root/src/test/ui/issues/issue-11205.rs
blob: ce0951eafdd346d46d92c29b1cfb0c9f021821a8 (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
// run-pass
// pretty-expanded FIXME #23616

#![allow(dead_code)]

trait Foo { fn dummy(&self) { } }
impl Foo for isize {}
fn foo(_: [&dyn Foo; 2]) {}
fn foos(_: &[&dyn Foo]) {}
fn foog<T>(_: &[T], _: &[T]) {}

fn bar(_: [Box<dyn Foo>; 2]) {}
fn bars(_: &[Box<dyn Foo+'static>]) {}

fn main() {
    let x: [&dyn Foo; 2] = [&1, &2];
    foo(x);
    foo([&1, &2]);

    let r = &1;
    let x: [&dyn Foo; 2] = [r; 2];
    foo(x);
    foo([&1; 2]);

    let x: &[&dyn Foo] = &[&1, &2];
    foos(x);
    foos(&[&1, &2]);

    let x: &[&dyn Foo] = &[&1, &2];
    let r = &1;
    foog(x, &[r]);

    let x: [Box<dyn Foo>; 2] = [Box::new(1), Box::new(2)];
    bar(x);
    bar([Box::new(1), Box::new(2)]);

    let x: &[Box<dyn Foo+'static>] = &[Box::new(1), Box::new(2)];
    bars(x);
    bars(&[Box::new(1), Box::new(2)]);

    let x: &[Box<dyn Foo+'static>] = &[Box::new(1), Box::new(2)];
    foog(x, &[Box::new(1)]);

    struct T<'a> {
        t: [&'a (dyn Foo+'a); 2]
    }
    let _n = T {
        t: [&1, &2]
    };
    let r = &1;
    let _n = T {
        t: [r; 2]
    };
    let x: [&dyn Foo; 2] = [&1, &2];
    let _n = T {
        t: x
    };

    struct F<'b> {
        t: &'b [&'b (dyn Foo+'b)]
    }
    let _n = F {
        t: &[&1, &2]
    };
    let r = &1;
    let r: [&dyn Foo; 2] = [r; 2];
    let _n = F {
        t: &r
    };
    let x: [&dyn Foo; 2] = [&1, &2];
    let _n = F {
        t: &x
    };

    struct M<'a> {
        t: &'a [Box<dyn Foo+'static>]
    }
    let _n = M {
        t: &[Box::new(1), Box::new(2)]
    };
    let x: [Box<dyn Foo>; 2] = [Box::new(1), Box::new(2)];
    let _n = M {
        t: &x
    };
}