-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add missing normalization for union fields types #106938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bors
merged 3 commits into
rust-lang:master
from
GuillaumeGomez:normalize-projection-field-ty
Feb 9, 2023
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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, | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would ICE if the union has fields which aren't well formed, e.g. something like
<T as NotImplemented>::Assoc
. Please add a test for this and check whether it currently causes an ICE. If so you can replace this withtry_normalize_erasing_regions
. I gues it's fine for normalization to ignore region obligations as we should detect these region errors in WF check.While this also ignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you mean:
Then no problem. I'll add a ui test for it though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure when exactly
normalize_erasing_regions
ends up failing with an ICE, only know that it does. Maybe also from something likeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working too, adding it as a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, alright. If there's a way to ICE here we will just get a bug report, so that seems fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dis you mean #107872 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦 yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That didn't take long. 🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Showed up as new in my daily ICE-screening ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job!