]> git.lizzy.rs Git - rust.git/commitdiff
Add failing test for invalid projection as union field type
authorGuillaume Gomez <guillaume.gomez@huawei.com>
Mon, 16 Jan 2023 17:10:11 +0000 (18:10 +0100)
committerGuillaume Gomez <guillaume.gomez@huawei.com>
Tue, 17 Jan 2023 13:00:55 +0000 (14:00 +0100)
tests/ui/union/projection-as-union-type-error-2.rs [new file with mode: 0644]
tests/ui/union/projection-as-union-type-error-2.stderr [new file with mode: 0644]
tests/ui/union/projection-as-union-type-error.rs [new file with mode: 0644]
tests/ui/union/projection-as-union-type-error.stderr [new file with mode: 0644]

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 (file)
index 0000000..b88167b
--- /dev/null
@@ -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 (file)
index 0000000..bab226f
--- /dev/null
@@ -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 (file)
index 0000000..17091c3
--- /dev/null
@@ -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 (file)
index 0000000..e4fbe96
--- /dev/null
@@ -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`.