]> git.lizzy.rs Git - rust.git/blob - src/test/ui/dst/dst-object-from-unsized-type.rs
Rollup merge of #57132 - daxpedda:master, r=steveklabnik
[rust.git] / src / test / ui / dst / dst-object-from-unsized-type.rs
1 // Test that we cannot create objects from unsized types.
2
3 trait Foo { fn foo(&self) {} }
4 impl Foo for str {}
5 impl Foo for [u8] {}
6
7 fn test1<T: ?Sized + Foo>(t: &T) {
8     let u: &Foo = t;
9     //~^ ERROR the size for values of type
10 }
11
12 fn test2<T: ?Sized + Foo>(t: &T) {
13     let v: &Foo = t as &Foo;
14     //~^ ERROR the size for values of type
15 }
16
17 fn test3() {
18     let _: &[&Foo] = &["hi"];
19     //~^ ERROR the size for values of type
20 }
21
22 fn test4(x: &[u8]) {
23     let _: &Foo = x as &Foo;
24     //~^ ERROR the size for values of type
25 }
26
27 fn main() { }