rust-lang / rust-lang/rust-analyzer
Parse validation is oblivious to macro calls
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Rust has two kings of parse errors:
- Pre-expansion parse errors, error that occur while parsing when something unexpected crops up
- Post-expansion parse errors (validation errors), parses that are rejected post macro expansion
The latter allows for stuff like unsafe mod foo {} to be accepted by attributes without issues, as long as they don't emit unsafe mod again. That is, unsafe mod is rejected in post expansion by validation. rustc does this by walking the fully expanded file tree with a validation pass. Our validation pass right now walks the unexpanded trees though which means we would (if we had a validation diagnostic for unsafe mod) diagnose the following:
#[cfg(False)]
unsafe mod m {}
where as rustc does not. The reason for this is mainl that rust-analyzer does not work on the fully expanded parse tree of a file, we keep the file parse and the macro parses separate so we need to figure something out here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the validation pass and how rust-analyzer keeps the file parse and macro parses separate, as described in the issue. Determine how validation can account for the fully expanded tree, and use the #[cfg(False)] unsafe mod example to verify behavior matches rustc.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100