rust-lang / rust-lang/rust

Decl macro parser reaching end of input reports as "found `<eof>`" which could be more descriptive

Open
#124,115 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Code
macro_rules! item {
    ($item:item) => {$item}
}
item!(mod x);
Current output
error: expected one of `;` or `{`, found `<eof>`
 --> src/lib.rs:4:11
  |
2 |     ($item:item) => {$item}
  |      ---------- while parsing argument for this `item` macro fragment
3 | }
4 | item!(mod x);
  |           ^ expected one of `;` or `{`

error: could not compile `playground` (lib) due to 1 previous error
Desired output
error: expected one of `;` or `{`, found end of macro input
 --> src/lib.rs:4:11
  |
2 |     ($item:item) => {$item}
  |      ---------- while parsing argument for this `item` macro fragment
3 | }
4 | item!(mod x);
  |            ^ expected one of `;` or `{`

error: could not compile `playground` (lib) due to 1 previous error
Rationale and extra context

<eof> doesn't necessarily tell people much. I imagine there might be newcomers who have no idea what this acronym is supposed to mean without googling it, it's also just an odd assortment of characters with the <> going on so I think we can improve on that :) Ideally it would also point to after the last token, since that last token was parsed correctly, though I guess that is difficult for implementation reasons.

In fact I just noticed we do the same outside of macros, that is a bare mod x in a file triggers the same so that might be good to adjust as well with a found end of file instead.

Other cases

No response

Rust Version
rustc 1.79.0-nightly (805813650 2024-03-31)
binary: rustc
commit-hash: 805813650248c1a2f6f271460d728d1bb852d2a7
commit-date: 2024-03-31
host: x86_64-pc-windows-msvc
release: 1.79.0-nightly
LLVM version: 18.1.2
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 macro example and the bare mod x case from the issue with the listed Rust version, then trace where the parser formats an unexpected EOF. Compare both diagnostics with the desired wording and span behavior. Done means EOF is described as the end of macro input or file rather than \u003ceof\u003e, with regression coverage for the affected cases.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.