From ea3c33942f04329593b7ab9f5d9268c2ce8935c6 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 31 May 2024 09:51:10 +0000 Subject: [PATCH] More tests --- .../impl-trait/unsized_coercion3.next.stderr | 9 +++++ .../impl-trait/unsized_coercion3.old.stderr | 26 +++++++++++++ tests/ui/impl-trait/unsized_coercion3.rs | 22 +++++++++++ tests/ui/impl-trait/unsized_coercion4.rs | 20 ++++++++++ .../impl-trait/unsized_coercion5.old.stderr | 38 +++++++++++++++++++ tests/ui/impl-trait/unsized_coercion5.rs | 25 ++++++++++++ 6 files changed, 140 insertions(+) create mode 100644 tests/ui/impl-trait/unsized_coercion3.next.stderr create mode 100644 tests/ui/impl-trait/unsized_coercion3.old.stderr create mode 100644 tests/ui/impl-trait/unsized_coercion3.rs create mode 100644 tests/ui/impl-trait/unsized_coercion4.rs create mode 100644 tests/ui/impl-trait/unsized_coercion5.old.stderr create mode 100644 tests/ui/impl-trait/unsized_coercion5.rs diff --git a/tests/ui/impl-trait/unsized_coercion3.next.stderr b/tests/ui/impl-trait/unsized_coercion3.next.stderr new file mode 100644 index 0000000000000..91b040424d6f3 --- /dev/null +++ b/tests/ui/impl-trait/unsized_coercion3.next.stderr @@ -0,0 +1,9 @@ +error[E0271]: type mismatch resolving `impl Trait + ?Sized <: dyn Send` + --> $DIR/unsized_coercion3.rs:13:17 + | +LL | let x = hello(); + | ^^^^^^^ types differ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0271`. diff --git a/tests/ui/impl-trait/unsized_coercion3.old.stderr b/tests/ui/impl-trait/unsized_coercion3.old.stderr new file mode 100644 index 0000000000000..24a302d7007ab --- /dev/null +++ b/tests/ui/impl-trait/unsized_coercion3.old.stderr @@ -0,0 +1,26 @@ +error: cannot check whether the hidden type of opaque type satisfies auto traits + --> $DIR/unsized_coercion3.rs:15:32 + | +LL | let y: Box = x; + | ^ + | + = note: fetching the hidden types of an opaque inside of the defining scope is not supported. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule +note: opaque type is declared here + --> $DIR/unsized_coercion3.rs:11:19 + | +LL | fn hello() -> Box { + | ^^^^^^^^^^^^^^^^^^^ + = note: required for the cast from `Box` to `Box` + +error[E0277]: the size for values of type `impl Trait + ?Sized` cannot be known at compilation time + --> $DIR/unsized_coercion3.rs:15:32 + | +LL | let y: Box = 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` to `Box` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/impl-trait/unsized_coercion3.rs b/tests/ui/impl-trait/unsized_coercion3.rs new file mode 100644 index 0000000000000..4b5c9ac65ff8a --- /dev/null +++ b/tests/ui/impl-trait/unsized_coercion3.rs @@ -0,0 +1,22 @@ +//! 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 + +trait Trait {} + +impl Trait for u32 {} + +fn hello() -> Box { + if true { + let x = hello(); + //[next]~^ ERROR: type mismatch resolving `impl Trait + ?Sized <: dyn Send` + let y: Box = x; + //[old]~^ ERROR: the size for values of type `impl Trait + ?Sized` cannot be know + //[old]~| ERROR: cannot check whether the hidden type of opaque type satisfies auto traits + } + Box::new(1u32) +} + +fn main() {} diff --git a/tests/ui/impl-trait/unsized_coercion4.rs b/tests/ui/impl-trait/unsized_coercion4.rs new file mode 100644 index 0000000000000..1c4d5462ceeb2 --- /dev/null +++ b/tests/ui/impl-trait/unsized_coercion4.rs @@ -0,0 +1,20 @@ +//! 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 +//@check-pass + +trait Trait {} + +impl Trait for u32 {} + +fn hello() -> Box { + if true { + let x = hello() as Box; + let y: Box = x; + } + Box::new(1u32) +} + +fn main() {} diff --git a/tests/ui/impl-trait/unsized_coercion5.old.stderr b/tests/ui/impl-trait/unsized_coercion5.old.stderr new file mode 100644 index 0000000000000..0267a5f5abc2f --- /dev/null +++ b/tests/ui/impl-trait/unsized_coercion5.old.stderr @@ -0,0 +1,38 @@ +error[E0308]: mismatched types + --> $DIR/unsized_coercion5.rs:17:32 + | +LL | let y: Box = x as Box; + | ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait `Send`, found trait `Trait + Send` + | | + | expected due to this + | + = note: expected struct `Box` + found struct `Box` + +error: cannot check whether the hidden type of opaque type satisfies auto traits + --> $DIR/unsized_coercion5.rs:17:32 + | +LL | let y: Box = x as Box; + | ^ + | + = note: fetching the hidden types of an opaque inside of the defining scope is not supported. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule +note: opaque type is declared here + --> $DIR/unsized_coercion5.rs:14:19 + | +LL | fn hello() -> Box { + | ^^^^^^^^^^^^^^^^^^^ + = note: required for the cast from `Box` to `Box` + +error[E0277]: the size for values of type `impl Trait + ?Sized` cannot be known at compilation time + --> $DIR/unsized_coercion5.rs:17:32 + | +LL | let y: Box = x as Box; + | ^ 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` to `Box` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0277, E0308. +For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/impl-trait/unsized_coercion5.rs b/tests/ui/impl-trait/unsized_coercion5.rs new file mode 100644 index 0000000000000..7d9575b7c37e8 --- /dev/null +++ b/tests/ui/impl-trait/unsized_coercion5.rs @@ -0,0 +1,25 @@ +//! 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 + +#![feature(trait_upcasting)] + +trait Trait {} + +impl Trait for u32 {} + +fn hello() -> Box { + if true { + let x = hello(); + let y: Box = x as Box; + //[old]~^ ERROR: the size for values of type `impl Trait + ?Sized` cannot be know + //[old]~| ERROR: mismatched types + //[old]~| ERROR: cannot check whether the hidden type of opaque type satisfies auto traits + } + Box::new(1u32) +} + +fn main() {}