rust/tests/ui/dst/dst-object-from-unsized-type.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

28 lines
567 B
Rust
Raw Normal View History

// Test that we cannot create objects from unsized types.
2015-02-18 23:58:07 +00:00
trait Foo { fn foo(&self) {} }
impl Foo for str {}
impl Foo for [u8] {}
2015-01-05 21:16:49 +00:00
fn test1<T: ?Sized + Foo>(t: &T) {
2019-05-28 18:46:13 +00:00
let u: &dyn Foo = t;
2018-07-10 21:10:13 +00:00
//~^ ERROR the size for values of type
}
2015-01-05 21:16:49 +00:00
fn test2<T: ?Sized + Foo>(t: &T) {
2019-05-28 18:46:13 +00:00
let v: &dyn Foo = t as &dyn Foo;
2018-07-10 21:10:13 +00:00
//~^ ERROR the size for values of type
}
fn test3() {
2019-05-28 18:46:13 +00:00
let _: &[&dyn Foo] = &["hi"];
2018-07-10 21:10:13 +00:00
//~^ ERROR the size for values of type
}
fn test4(x: &[u8]) {
2019-05-28 18:46:13 +00:00
let _: &dyn Foo = x as &dyn Foo;
2018-07-10 21:10:13 +00:00
//~^ ERROR the size for values of type
}
fn main() { }