summaryrefslogtreecommitdiffstats
path: root/src/test/ui/wf/wf-convert-unsafe-trait-obj-box.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/wf/wf-convert-unsafe-trait-obj-box.rs')
-rw-r--r--src/test/ui/wf/wf-convert-unsafe-trait-obj-box.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/test/ui/wf/wf-convert-unsafe-trait-obj-box.rs b/src/test/ui/wf/wf-convert-unsafe-trait-obj-box.rs
new file mode 100644
index 000000000..ffdb49a3b
--- /dev/null
+++ b/src/test/ui/wf/wf-convert-unsafe-trait-obj-box.rs
@@ -0,0 +1,18 @@
+// Check that we do not allow casts or coercions
+// to object unsafe trait objects inside a Box
+
+#![feature(object_safe_for_dispatch)]
+
+trait Trait: Sized {}
+
+struct S;
+
+impl Trait for S {}
+
+fn takes_box(t: Box<dyn Trait>) {}
+
+fn main() {
+ Box::new(S) as Box<dyn Trait>; //~ ERROR E0038
+ let t_box: Box<dyn Trait> = Box::new(S); //~ ERROR E0038
+ takes_box(Box::new(S)); //~ ERROR E0038
+}