about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--tests/ui/impl-trait/unsized_coercion.next.stderr26
-rw-r--r--tests/ui/impl-trait/unsized_coercion.rs21
-rw-r--r--tests/ui/impl-trait/unsized_coercion2.old.stderr12
-rw-r--r--tests/ui/impl-trait/unsized_coercion2.rs21
4 files changed, 80 insertions, 0 deletions
diff --git a/tests/ui/impl-trait/unsized_coercion.next.stderr b/tests/ui/impl-trait/unsized_coercion.next.stderr
new file mode 100644
index 00000000000..49ac3f1845f
--- /dev/null
+++ b/tests/ui/impl-trait/unsized_coercion.next.stderr
@@ -0,0 +1,26 @@
+error[E0271]: type mismatch resolving `impl Trait <: dyn Trait`
+  --> $DIR/unsized_coercion.rs:14:17
+   |
+LL |         let x = hello();
+   |                 ^^^^^^^ types differ
+
+error[E0308]: mismatched types
+  --> $DIR/unsized_coercion.rs:18:14
+   |
+LL | fn hello() -> Box<impl Trait> {
+   |                   ---------- the expected opaque type
+...
+LL |     Box::new(1u32)
+   |     -------- ^^^^ types differ
+   |     |
+   |     arguments to this function are incorrect
+   |
+   = note: expected opaque type `impl Trait`
+                     found type `u32`
+note: associated function defined here
+  --> $SRC_DIR/alloc/src/boxed.rs:LL:COL
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0271, E0308.
+For more information about an error, try `rustc --explain E0271`.
diff --git a/tests/ui/impl-trait/unsized_coercion.rs b/tests/ui/impl-trait/unsized_coercion.rs
new file mode 100644
index 00000000000..46e040c1428
--- /dev/null
+++ b/tests/ui/impl-trait/unsized_coercion.rs
@@ -0,0 +1,21 @@
+//! This test checks that opaque types get unsized instead of
+//! constraining their hidden type to a trait object.
+
+//@ revisions: next old
+//@[next] compile-flags: -Znext-solver
+//@[old] check-pass
+
+trait Trait {}
+
+impl Trait for u32 {}
+
+fn hello() -> Box<impl Trait> {
+    if true {
+        let x = hello();
+        //[next]~^ ERROR: type mismatch resolving `impl Trait <: dyn Trait`
+        let y: Box<dyn Trait> = x;
+    }
+    Box::new(1u32) //[next]~ ERROR: mismatched types
+}
+
+fn main() {}
diff --git a/tests/ui/impl-trait/unsized_coercion2.old.stderr b/tests/ui/impl-trait/unsized_coercion2.old.stderr
new file mode 100644
index 00000000000..a89d40f1130
--- /dev/null
+++ b/tests/ui/impl-trait/unsized_coercion2.old.stderr
@@ -0,0 +1,12 @@
+error[E0277]: the size for values of type `impl Trait + ?Sized` cannot be known at compilation time
+  --> $DIR/unsized_coercion2.rs:15:33
+   |
+LL |         let y: Box<dyn Trait> = x;
+   |                                 ^ doesn't have a size known at compile-time
+   |
+   = help: the trait `Sized` is not implemented for `impl Trait + ?Sized`
+   = note: required for the cast from `Box<impl Trait + ?Sized>` to `Box<dyn Trait>`
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/impl-trait/unsized_coercion2.rs b/tests/ui/impl-trait/unsized_coercion2.rs
new file mode 100644
index 00000000000..7368d47dbe2
--- /dev/null
+++ b/tests/ui/impl-trait/unsized_coercion2.rs
@@ -0,0 +1,21 @@
+//! This test checks that opaque types get unsized instead of
+//! constraining their hidden type to a trait object.
+
+//@ revisions: next old
+//@[next] compile-flags: -Znext-solver
+//@[next] check-pass
+
+trait Trait {}
+
+impl Trait for u32 {}
+
+fn hello() -> Box<impl Trait + ?Sized> {
+    if true {
+        let x = hello();
+        let y: Box<dyn Trait> = x;
+        //[old]~^ ERROR: the size for values of type `impl Trait + ?Sized` cannot be know
+    }
+    Box::new(1u32)
+}
+
+fn main() {}