summaryrefslogtreecommitdiffstats
path: root/src/test/ui/dst/dst-object-from-unsized-type.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/dst/dst-object-from-unsized-type.rs')
-rw-r--r--src/test/ui/dst/dst-object-from-unsized-type.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/test/ui/dst/dst-object-from-unsized-type.rs b/src/test/ui/dst/dst-object-from-unsized-type.rs
new file mode 100644
index 000000000..3cd5b1ed6
--- /dev/null
+++ b/src/test/ui/dst/dst-object-from-unsized-type.rs
@@ -0,0 +1,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() { }