diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:41 +0000 |
commit | 4f9fe856a25ab29345b90e7725509e9ee38a37be (patch) | |
tree | e4ffd8a9374cae7b21f7cbfb352927e0e074aff6 /tests/ui/union | |
parent | Adding upstream version 1.68.2+dfsg1. (diff) | |
download | rustc-upstream/1.69.0+dfsg1.tar.xz rustc-upstream/1.69.0+dfsg1.zip |
Adding upstream version 1.69.0+dfsg1.upstream/1.69.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | tests/ui/union/projection-as-union-type-error-2.rs | 20 | ||||
-rw-r--r-- | tests/ui/union/projection-as-union-type-error-2.stderr | 17 | ||||
-rw-r--r-- | tests/ui/union/projection-as-union-type-error.rs | 15 | ||||
-rw-r--r-- | tests/ui/union/projection-as-union-type-error.stderr | 9 | ||||
-rw-r--r-- | tests/ui/union/projection-as-union-type.rs | 19 |
5 files changed, 80 insertions, 0 deletions
diff --git a/tests/ui/union/projection-as-union-type-error-2.rs b/tests/ui/union/projection-as-union-type-error-2.rs new file mode 100644 index 000000000..b88167b3b --- /dev/null +++ b/tests/ui/union/projection-as-union-type-error-2.rs @@ -0,0 +1,20 @@ +// Test to ensure that there is no ICE when normalizing a projection +// which is invalid (from <https://github.com/rust-lang/rust/pull/106938>). + +#![crate_type = "lib"] + +trait Identity { + type Identity; +} +trait NotImplemented {} + +impl<T: NotImplemented> Identity for T { + type Identity = Self; +} + +type Foo = u8; + +union Bar { + a: <Foo as Identity>::Identity, //~ ERROR + b: u8, +} diff --git a/tests/ui/union/projection-as-union-type-error-2.stderr b/tests/ui/union/projection-as-union-type-error-2.stderr new file mode 100644 index 000000000..bab226f27 --- /dev/null +++ b/tests/ui/union/projection-as-union-type-error-2.stderr @@ -0,0 +1,17 @@ +error[E0277]: the trait bound `u8: NotImplemented` is not satisfied + --> $DIR/projection-as-union-type-error-2.rs:18:8 + | +LL | a: <Foo as Identity>::Identity, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotImplemented` is not implemented for `u8` + | +note: required for `u8` to implement `Identity` + --> $DIR/projection-as-union-type-error-2.rs:11:25 + | +LL | impl<T: NotImplemented> Identity for T { + | -------------- ^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/union/projection-as-union-type-error.rs b/tests/ui/union/projection-as-union-type-error.rs new file mode 100644 index 000000000..17091c35f --- /dev/null +++ b/tests/ui/union/projection-as-union-type-error.rs @@ -0,0 +1,15 @@ +// Test to ensure that there is no ICE when normalizing a projection +// which is invalid (from <https://github.com/rust-lang/rust/pull/106938>). + +#![crate_type = "lib"] + +pub trait Identity { + type Identity; +} + +pub type Foo = u8; + +pub union Bar { + a: <Foo as Identity>::Identity, //~ ERROR + b: u8, +} diff --git a/tests/ui/union/projection-as-union-type-error.stderr b/tests/ui/union/projection-as-union-type-error.stderr new file mode 100644 index 000000000..e4fbe9603 --- /dev/null +++ b/tests/ui/union/projection-as-union-type-error.stderr @@ -0,0 +1,9 @@ +error[E0277]: the trait bound `u8: Identity` is not satisfied + --> $DIR/projection-as-union-type-error.rs:13:9 + | +LL | a: <Foo as Identity>::Identity, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Identity` is not implemented for `u8` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/union/projection-as-union-type.rs b/tests/ui/union/projection-as-union-type.rs new file mode 100644 index 000000000..143434c96 --- /dev/null +++ b/tests/ui/union/projection-as-union-type.rs @@ -0,0 +1,19 @@ +// Ensures that we can use projections as union field's type. +// check-pass + +#![crate_type = "lib"] + +pub trait Identity { + type Identity; +} + +impl<T> Identity for T { + type Identity = Self; +} + +pub type Foo = u8; + +pub union Bar { + pub a: <Foo as Identity>::Identity, + pub b: u8, +} |