-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #106938 - GuillaumeGomez:normalize-projection-field-ty,…
… r=oli-obk Add missing normalization for union fields types Overshadows #106808. From the experiment #103985. In short, it allows to use projections as a type for union's fields. cc `@compiler-errors` r? `@oli-obk`
- Loading branch information
Showing
6 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} |