Skip to content

parse type const items#22046

Merged
Veykril merged 1 commit intorust-lang:masterfrom
yPin9:2026-04-15-parse-type-const
Apr 15, 2026
Merged

parse type const items#22046
Veykril merged 1 commit intorust-lang:masterfrom
yPin9:2026-04-15-parse-type-const

Conversation

@yPin9
Copy link
Copy Markdown
Contributor

@yPin9 yPin9 commented Apr 14, 2026

Adds parser support for the unstable type const syntax from the
min_generic_const_args feature:

#![feature(min_generic_const_args)]
type const FOO: i32 = 2;

Previously rust-analyzer reported 8 syntax errors on this valid (nightly) code.

Closes #22038.

Changes

  • rust.ungram: add optional 'type'? before 'const' in the Const rule.
  • parser/grammar/items.rs: dispatch type followed by const to consts::konst in both item match sites (covers type const FOO and default type const FOO).
  • parser/grammar/items/consts.rs: konst now p.eat(T![type]) before bumping const.
  • Inline test type_const added; cargo xtask codegen regenerated AST nodes and test runner.

Test plan

  • cargo test -p parser (including new type_const test)
  • cargo test -p syntax
  • Manual end-to-end check via rust-analyzer parse on the full issue reproduction — zero errors, correct CONST node with TYPE_KW + CONST_KW.
  • Negative case (type const: i32 = 2;) still emits errors.

Assisted-by: Claude Opus 4.6

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 14, 2026
@rustbot

This comment has been minimized.

Adds parser support for the unstable `type const` syntax from the
`min_generic_const_args` feature, e.g. `type const FOO: i32 = 2;`.

Closes rust-lang#22038.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@yPin9 yPin9 force-pushed the 2026-04-15-parse-type-const branch from 7f5886f to b4f32b4 Compare April 14, 2026 16:18
@Veykril Veykril added this pull request to the merge queue Apr 15, 2026
Merged via the queue into rust-lang:master with commit 5926ac2 Apr 15, 2026
18 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 15, 2026
@reddevilmidzy
Copy link
Copy Markdown
Member

Hello @yPin9, it seems I am still getting syntax errors in my rust-analyzer. How about you?

@ShoyuVanilla
Copy link
Copy Markdown
Member

Hello @yPin9, it seems I am still getting syntax errors in my rust-analyzer. How about you?

Which version are you on? As this haven't been included in our stable releases (every Monday) yet, the issue wouldn't be fixed unless you are using the nightly release of rust-analyzer or have built it from the source

@reddevilmidzy
Copy link
Copy Markdown
Member

Which version are you on? As this haven't been included in our stable releases (every Monday) yet, the issue wouldn't be fixed unless you are using the nightly release of rust-analyzer or have built it from the source

Ah, when I ran rust-analyzer --version, it showed rust-analyzer 1.97.0-nightly (e9e32aca 2026-04-17), so I thought the changes had been updated, but it seems the changes to r-l/r haven't arrived yet.

@ShoyuVanilla
Copy link
Copy Markdown
Member

Yeah, we usually do subtree updates to rust-lang/rust on every Monday, after stable release

@ShoyuVanilla
Copy link
Copy Markdown
Member

Yeah, we usually do subtree updates to rust-lang/rust on every Monday, after stable release

This is it rust-lang/rust#155556

@reddevilmidzy
Copy link
Copy Markdown
Member

Yeah, we usually do subtree updates to rust-lang/rust on every Monday, after stable release

This is it rust-lang/rust#155556

thanks! I should update it quickly 😁

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.

Syntax error when using 'type const'

5 participants