-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Fix ICE on { _ } const args in bodies by tracking const-only infer args #160984
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
rust-bors
merged 6 commits into
rust-lang:main
from
bit-aloo:2026-08-12-mgca-const-infer-args
Aug 14, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
69361d7
Track whether a `GenericArg::Infer` is written in const argument syntax
bit-aloo 4147cde
Handle anon const defs attached to `Node::Infer` under mGCA
bit-aloo 90e8747
Reject const infer used for type parameters
bit-aloo 4b9e6a5
Add regression test and fallout
bit-aloo cbe18c5
allocate generic args to arena
bit-aloo aa60548
Add docs for InferArgKind, explaining the rational
bit-aloo 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
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
23 changes: 23 additions & 0 deletions
23
tests/ui/const-generics/mgca/braced-const-infer-in-body.rs
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,23 @@ | ||
| //! Regression test for: https://github.com/rust-lang/rust/issues/160798 | ||
| #![crate_type = "lib"] | ||
| #![feature(min_generic_const_args)] | ||
| #![feature(macroless_generic_const_args)] | ||
|
|
||
| trait Trait<T> {} | ||
|
|
||
| impl Trait<i32> for i32 {} | ||
|
|
||
| struct S<const N: usize>; | ||
|
|
||
| fn main() { | ||
| // Const-only infer args used for a type parameter are rejected. | ||
| let _z: &[&dyn Trait<{ _ }>] = &[&0i32]; | ||
| //~^ ERROR: constant provided when a type was expected | ||
| let _y: &dyn Trait<core::direct_const_arg!(_)> = &0i32; | ||
| //~^ ERROR: constant provided when a type was expected | ||
|
|
||
| let _a: S<{ _ }> = S::<3>; | ||
| let _b: S<core::direct_const_arg!(_)> = S::<3>; | ||
| let _c: S<{ core::direct_const_arg!(_) }> = S::<3>; | ||
| let _d: S<_> = S::<3>; | ||
| } |
15 changes: 15 additions & 0 deletions
15
tests/ui/const-generics/mgca/braced-const-infer-in-body.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,15 @@ | ||
| error[E0747]: constant provided when a type was expected | ||
| --> $DIR/braced-const-infer-in-body.rs:14:28 | ||
| | | ||
| LL | let _z: &[&dyn Trait<{ _ }>] = &[&0i32]; | ||
| | ^ | ||
|
|
||
| error[E0747]: constant provided when a type was expected | ||
| --> $DIR/braced-const-infer-in-body.rs:16:48 | ||
| | | ||
| LL | let _y: &dyn Trait<core::direct_const_arg!(_)> = &0i32; | ||
| | ^ | ||
|
|
||
| error: aborting due to 2 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0747`. |
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,9 +1,9 @@ | ||
| error[E0121]: the placeholder `_` is not allowed within types on item signatures for implementations | ||
| error[E0747]: constant provided when a type was expected | ||
| --> $DIR/braced-const-infer.rs:7:17 | ||
| | | ||
| LL | impl dyn Trait<{_}> {} | ||
| | ^ not allowed in type signatures | ||
| | ^ | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0121`. | ||
| For more information about this error, try `rustc --explain E0747`. |
9 changes: 5 additions & 4 deletions
9
tests/ui/const-generics/mgca/direct_const_arg-infer-as-type.rs
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,12 +1,13 @@ | ||
| //@ check-pass | ||
| //! It is very weird and mostly a compiler implementation quirk that direct_const_arg!(_) is allowed | ||
| //! to infer to a type rather than forcing it to be a constant. This test simply tracks/asserts the | ||
| //! current behavior. | ||
| //! `direct_const_arg!(_)` used to be allowed to infer to a type as a compiler | ||
| //! implementation quirk. Since it uses explicit const argument syntax, | ||
| //! it is now rejected when passed as a type argument | ||
| #![feature(min_generic_const_args)] | ||
|
|
||
| struct S<T>(T); | ||
|
|
||
| fn main() { | ||
| let _: S<core::direct_const_arg!(_)> = S(2u32); | ||
| //~^ ERROR: constant provided when a type was expected | ||
| let _: S<{ core::direct_const_arg!(_) }> = S(2u32); | ||
| //~^ ERROR: constant provided when a type was expected | ||
| } |
15 changes: 15 additions & 0 deletions
15
tests/ui/const-generics/mgca/direct_const_arg-infer-as-type.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,15 @@ | ||
| error[E0747]: constant provided when a type was expected | ||
| --> $DIR/direct_const_arg-infer-as-type.rs:9:38 | ||
| | | ||
| LL | let _: S<core::direct_const_arg!(_)> = S(2u32); | ||
| | ^ | ||
|
|
||
| error[E0747]: constant provided when a type was expected | ||
| --> $DIR/direct_const_arg-infer-as-type.rs:11:40 | ||
| | | ||
| LL | let _: S<{ core::direct_const_arg!(_) }> = S(2u32); | ||
| | ^ | ||
|
|
||
| error: aborting due to 2 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0747`. |
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
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.
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.
maybe a short comment here, explaining the purpose of this, if there's no other comment elsewhere in code - "
S::<_>is allowed to infer to either a type or a const, butS::<{ _ }>must infer to a constant, so this tracks that" kind of thing, idk exact phrasing. just, having concrete examples of "why is this a thing / when does it happen" is super useful for me personally when reading code!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.
Added a short description.