diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-05-31 09:51:10 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-06-19 08:40:29 +0000 |
| commit | 45da03541c0a07f63f1b8c15cccd2fc8692cca7e (patch) | |
| tree | ef2e44810afdeda56f6c74d858ba63de4aaec8c2 | |
| parent | f5f298dad4f8ed383cac22d90659b55a820f7ba0 (diff) | |
| download | rust-45da03541c0a07f63f1b8c15cccd2fc8692cca7e.tar.gz rust-45da03541c0a07f63f1b8c15cccd2fc8692cca7e.zip | |
More tests
| -rw-r--r-- | tests/ui/impl-trait/unsized_coercion3.next.stderr | 38 | ||||
| -rw-r--r-- | tests/ui/impl-trait/unsized_coercion3.old.stderr | 26 | ||||
| -rw-r--r-- | tests/ui/impl-trait/unsized_coercion3.rs | 24 | ||||
| -rw-r--r-- | tests/ui/impl-trait/unsized_coercion4.rs | 20 | ||||
| -rw-r--r-- | tests/ui/impl-trait/unsized_coercion5.next.stderr | 14 | ||||
| -rw-r--r-- | tests/ui/impl-trait/unsized_coercion5.old.stderr | 38 | ||||
| -rw-r--r-- | tests/ui/impl-trait/unsized_coercion5.rs | 24 |
7 files changed, 184 insertions, 0 deletions
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 00000000000..bab8d1cd83b --- /dev/null +++ b/tests/ui/impl-trait/unsized_coercion3.next.stderr @@ -0,0 +1,38 @@ +error[E0271]: type mismatch resolving `impl Trait + ?Sized <: dyn Send` + --> $DIR/unsized_coercion3.rs:13:17 + | +LL | let x = hello(); + | ^^^^^^^ types differ + +error[E0308]: mismatched types + --> $DIR/unsized_coercion3.rs:19:14 + | +LL | fn hello() -> Box<impl Trait + ?Sized> { + | ------------------- the expected opaque type +... +LL | Box::new(1u32) + | -------- ^^^^ types differ + | | + | arguments to this function are incorrect + | + = note: expected opaque type `impl Trait + ?Sized` + found type `u32` +note: associated function defined here + --> $SRC_DIR/alloc/src/boxed.rs:LL:COL + +error[E0277]: the size for values of type `impl Trait + ?Sized` cannot be known at compilation time + --> $DIR/unsized_coercion3.rs:19:14 + | +LL | Box::new(1u32) + | -------- ^^^^ doesn't have a size known at compile-time + | | + | required by a bound introduced by this call + | + = help: the trait `Sized` is not implemented for `impl Trait + ?Sized` +note: required by a bound in `Box::<T>::new` + --> $SRC_DIR/alloc/src/boxed.rs:LL:COL + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0271, E0277, E0308. +For more information about an 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 00000000000..24a302d7007 --- /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<dyn Send> = 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<impl Trait + ?Sized> { + | ^^^^^^^^^^^^^^^^^^^ + = note: required for the cast from `Box<impl Trait + ?Sized>` to `Box<dyn Send>` + +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<dyn Send> = 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 Send>` + +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 00000000000..85950ac583e --- /dev/null +++ b/tests/ui/impl-trait/unsized_coercion3.rs @@ -0,0 +1,24 @@ +//! 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<impl Trait + ?Sized> { + if true { + let x = hello(); + //[next]~^ ERROR: type mismatch resolving `impl Trait + ?Sized <: dyn Send` + let y: Box<dyn Send> = 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) + //[next]~^ ERROR: mismatched types + //[next]~| ERROR: the size for values of type `impl Trait + ?Sized` cannot be know +} + +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 00000000000..1c4d5462cee --- /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<impl Trait + ?Sized> { + if true { + let x = hello() as Box<u32>; + let y: Box<dyn Send> = x; + } + Box::new(1u32) +} + +fn main() {} diff --git a/tests/ui/impl-trait/unsized_coercion5.next.stderr b/tests/ui/impl-trait/unsized_coercion5.next.stderr new file mode 100644 index 00000000000..5644ac7ab04 --- /dev/null +++ b/tests/ui/impl-trait/unsized_coercion5.next.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/unsized_coercion5.rs:16:32 + | +LL | let y: Box<dyn Send> = x as Box<dyn Trait + Send>; + | ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait `Send`, found trait `Trait + Send` + | | + | expected due to this + | + = note: expected struct `Box<dyn Send>` + found struct `Box<dyn Trait + Send>` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. 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 00000000000..b6437266f27 --- /dev/null +++ b/tests/ui/impl-trait/unsized_coercion5.old.stderr @@ -0,0 +1,38 @@ +error[E0308]: mismatched types + --> $DIR/unsized_coercion5.rs:16:32 + | +LL | let y: Box<dyn Send> = x as Box<dyn Trait + Send>; + | ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait `Send`, found trait `Trait + Send` + | | + | expected due to this + | + = note: expected struct `Box<dyn Send>` + found struct `Box<dyn Trait + Send>` + +error: cannot check whether the hidden type of opaque type satisfies auto traits + --> $DIR/unsized_coercion5.rs:16:32 + | +LL | let y: Box<dyn Send> = x as Box<dyn Trait + Send>; + | ^ + | + = 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:13:19 + | +LL | fn hello() -> Box<impl Trait + ?Sized> { + | ^^^^^^^^^^^^^^^^^^^ + = note: required for the cast from `Box<impl Trait + ?Sized>` to `Box<dyn Trait + Send>` + +error[E0277]: the size for values of type `impl Trait + ?Sized` cannot be known at compilation time + --> $DIR/unsized_coercion5.rs:16:32 + | +LL | let y: Box<dyn Send> = x as Box<dyn Trait + Send>; + | ^ 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 + Send>` + +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 00000000000..b007267a006 --- /dev/null +++ b/tests/ui/impl-trait/unsized_coercion5.rs @@ -0,0 +1,24 @@ +//! 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 + +#![feature(trait_upcasting)] + +trait Trait {} + +impl Trait for u32 {} + +fn hello() -> Box<impl Trait + ?Sized> { + if true { + let x = hello(); + let y: Box<dyn Send> = x as Box<dyn Trait + Send>; + //[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 + //~^^^ ERROR: mismatched types + } + Box::new(1u32) +} + +fn main() {} |
