summaryrefslogtreecommitdiffstats
path: root/src/test/ui/dst/dst-object-from-unsized-type.rs
blob: 3cd5b1ed6f46232475c7e7c42dc68c876db30f7a (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
// Test that we cannot create objects from unsized types.

trait Foo { fn foo(&self) {} }
impl Foo for str {}
impl Foo for [u8] {}

fn test1<T: ?Sized + Foo>(t: &T) {
    let u: &dyn Foo = t;
    //~^ ERROR the size for values of type
}

fn test2<T: ?Sized + Foo>(t: &T) {
    let v: &dyn Foo = t as &dyn Foo;
    //~^ ERROR the size for values of type
}

fn test3() {
    let _: &[&dyn Foo] = &["hi"];
    //~^ ERROR the size for values of type
}

fn test4(x: &[u8]) {
    let _: &dyn Foo = x as &dyn Foo;
    //~^ ERROR the size for values of type
}

fn main() { }