rust-lang / rust-lang/rust

Bad parse error on many token sequences

Open
#136,100 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics A-parser T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
// This is the only one i've found for now
async const FOO: () = ();
Current output
error: expected one of `extern`, `fn`, `gen`, `safe`, or `unsafe`, found keyword `const`
 --> src/main.rs:8:7
  |
8 | async const FOO: () = ();
  | ------^^^^^
  | |     |
  | |     expected one of `extern`, `fn`, `gen`, `safe`, or `unsafe`
  | help: `const` must come before `async`: `const async`
  |
  = note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
Desired output
error: expected one of `fn`, `gen`, `unsafe`, ..., found keyword `const`
--> src/main.rs:8:7
   |
 8 | async const FOO: () = ();
   | ------^^^^^
   | |     |
   | |     unexpected item
   = note: constants cannot be `async`
Rationale and extra context

this is meant to be a more general version of #134580

as opposed to #134580, however, this does not apply to const async, which is better

Other cases
TODO: add more cases
Rust Version
$ rustc --version --verbose
rustc 1.86.0-nightly (48a426eca 2025-01-12)
binary: rustc
commit-hash: 48a426eca9df23b24b3559e545cf88dee61d4de9
commit-date: 2025-01-12
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.6
Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the async const FOO: () = (); snippet with the reported rustc nightly version and compare the current and desired diagnostics. Done means the parser reports that constants cannot be async and handles the broader token-sequence cases without regressing the accepted const async case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.