-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
dont create unnecessary DefIds under mgca
#150025
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
+71
−15
Merged
Changes from all commits
Commits
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
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 |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| #![feature(associated_const_equality, generic_const_items, min_generic_const_args)] | ||
| #![expect(incomplete_features)] | ||
| // library crates exercise weirder code paths around | ||
| // DefIds which were created for const args. | ||
| #![crate_type = "lib"] | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. annoying that I literally went out of my way to add test cases for the ICEing code to catch stuff like this but it just didn't matter because the ICE occurs during metadata encoding or sth instead of some kind of HIR validation step |
||
|
|
||
| struct Foo<const N: usize>; | ||
|
|
||
|
|
@@ -66,5 +69,3 @@ struct Default3<const N: usize, const M: usize = const { N }>; | |
| struct Default4<const N: usize, const M: usize = { 1 + 1 }>; | ||
| //~^ ERROR: complex const arguments must be placed inside of a `const` block | ||
| struct Default5<const N: usize, const M: usize = const { 1 + 1}>; | ||
|
|
||
| fn main() {} | ||
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,24 @@ | ||
| #![feature(min_generic_const_args, generic_const_exprs, generic_const_items)] | ||
| #![expect(incomplete_features)] | ||
|
|
||
| // Previously we would create a `DefId` to represent the const argument to `A` | ||
| // except it would go unused as it's a MGCA path const arg. We would also make | ||
| // a `DefId` for the `const { 1 }` anon const arg to `ERR` which would wind up | ||
| // with a `DefId` parent of the speculatively created `DefId` for the argument to | ||
| // `A`. | ||
| // | ||
| // This then caused Problems:tm: in the rest of the compiler that did not expect | ||
| // to encounter such nonsensical `DefId`s. | ||
| // | ||
| // The `ERR` path must fail to resolve as if it can be resolved then broken GCE | ||
| // logic will attempt to evaluate the constant directly which is wrong for | ||
| // `type_const`s which do not have bodies. | ||
|
|
||
| struct A<const N: usize>; | ||
|
|
||
| struct Foo { | ||
| field: A<{ ERR::<const { 1 }> }>, | ||
| //~^ ERROR: cannot find value `ERR` in this scope | ||
| } | ||
|
|
||
| fn main() {} |
18 changes: 18 additions & 0 deletions
18
tests/ui/const-generics/mgca/unused_speculative_def_id.stderr
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,18 @@ | ||
| error[E0425]: cannot find value `ERR` in this scope | ||
| --> $DIR/unused_speculative_def_id.rs:20:16 | ||
| | | ||
| LL | field: A<{ ERR::<const { 1 }> }>, | ||
| | ^^^ | ||
| | | ||
| --> $SRC_DIR/core/src/result.rs:LL:COL | ||
| | | ||
| = note: similarly named tuple variant `Err` defined here | ||
| help: a tuple variant with a similar name exists | ||
| | | ||
| LL - field: A<{ ERR::<const { 1 }> }>, | ||
| LL + field: A<{ Err::<const { 1 }> }>, | ||
| | | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0425`. |
Oops, something went wrong.
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.
Is the additional feature gate check necessary?
Uh oh!
There was an error while loading. Please reload this page.
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.
Yep, we can't set
MgcaDisambiguationdifferently depending on whether the feature gate is enabled or not (as the parser doesn't have access to such information). So the enum is really a "if mgca is enabled, this should/shouldnt be an anon const", without mgca enabled the enum is basically meaningless