Skip to content

Commit 6c63b94

Browse files
Add failing test for invalid projection as union field type
1 parent 4653bbf commit 6c63b94

4 files changed

+61
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Test to ensure that there is no ICE when normalizing a projection
2+
// which is invalid (from <https://github.com/rust-lang/rust/pull/106938>).
3+
4+
#![crate_type = "lib"]
5+
6+
trait Identity {
7+
type Identity;
8+
}
9+
trait NotImplemented {}
10+
11+
impl<T: NotImplemented> Identity for T {
12+
type Identity = Self;
13+
}
14+
15+
type Foo = u8;
16+
17+
union Bar {
18+
a: <Foo as Identity>::Identity, //~ ERROR
19+
b: u8,
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: the trait bound `u8: NotImplemented` is not satisfied
2+
--> $DIR/projection-as-union-type-error-2.rs:18:8
3+
|
4+
LL | a: <Foo as Identity>::Identity,
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotImplemented` is not implemented for `u8`
6+
|
7+
note: required for `u8` to implement `Identity`
8+
--> $DIR/projection-as-union-type-error-2.rs:11:25
9+
|
10+
LL | impl<T: NotImplemented> Identity for T {
11+
| -------------- ^^^^^^^^ ^
12+
| |
13+
| unsatisfied trait bound introduced here
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Test to ensure that there is no ICE when normalizing a projection
2+
// which is invalid (from <https://github.com/rust-lang/rust/pull/106938>).
3+
4+
#![crate_type = "lib"]
5+
6+
pub trait Identity {
7+
type Identity;
8+
}
9+
10+
pub type Foo = u8;
11+
12+
pub union Bar {
13+
a: <Foo as Identity>::Identity, //~ ERROR
14+
b: u8,
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0277]: the trait bound `u8: Identity` is not satisfied
2+
--> $DIR/projection-as-union-type-error.rs:13:9
3+
|
4+
LL | a: <Foo as Identity>::Identity,
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Identity` is not implemented for `u8`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)