Skip to content

Fix the grammar of const param defaults by reusing rule for const args#2270

Draft
fmease wants to merge 1 commit into
rust-lang:masterfrom
fmease:const-arg
Draft

Fix the grammar of const param defaults by reusing rule for const args#2270
fmease wants to merge 1 commit into
rust-lang:masterfrom
fmease:const-arg

Conversation

@fmease
Copy link
Copy Markdown
Member

@fmease fmease commented May 11, 2026

struct T<const N: U = crate>; is syntactically valid but the previous definition of rule ConstParam didn't capture that fact since it only listed IDENTIFIER while it needed to be SimplePathSegment.

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label May 11, 2026
Comment thread src/paths.md
Lifetime | Type | ConstArg | GenericArgsBinding | GenericArgsBounds
GenericArgsConst ->
ConstArg ->
Copy link
Copy Markdown
Member Author

@fmease fmease May 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const arg / constant argument is the term we use in rustc (internally and in diagnostics).

Moreover, in rustc's parser, const arg doesn't just refer to const arguments literally but also to const param defaults (and to the RHS of associated const bindings as in TraitRef<CT = { 1 + 1 }> but that's unstable syntax). So "reusing" ConstArg in rule ConstParam doesn't come out of thin air.

View changes since the review

`struct T<const N: U = crate>;` is syntactically valid but the previous
definition of rule *ConstParam* didn't capture that fact since it listed
*IDENTIFIER* while it needed to be *SimplePathSegment*.
@fmease fmease marked this pull request as draft May 12, 2026 09:47
@rustbot rustbot removed the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label May 12, 2026
@fmease
Copy link
Copy Markdown
Member Author

fmease commented May 12, 2026

I found an issue: The "const arg" used for the param default should include Self while the "const arg proper" should not contain Self as that would conflict with type arguments. Let me think about how to solve this most nicely.

Edit: Well, as a matter of fact, GenericArgsConst already conflicts with Type on master ... I think remember a Zulip or GH discussion where ehuss (?) stated that it's still unclear how we want to represent identifier const args that can refer to either type or const in the grammar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants