rust-lang / rust-lang/rust-analyzer
Failure to parse macro converting a `stmt` into a `block`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
rust-analyzer version: rust-analyzer version: 5e8515870 2022-03-14 stable
rustc version: rustc 1.59.0 (9d1b2106e 2022-02-23)
relevant settings: don't think I have anything custom
More or less minimal example:
fn main() {
macro_rules! parse {
($action:block) => ($action);
($action:stmt) => (
parse!({ $action })
);
}
parse!(let _ = 1);
}
rust-analyzer errors with "expected Block", meanwhile rustc expands this fine into:
fn main() {
{
let _ = 1;
};
}
Adding ; manually, i.e. parse!({ $action; }), makes r-a parse/expand it correctly but produces an "unnecessary trailing semicolon" warning.
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 with the minimal macro_rules! parse! reproducer in the issue and compare rust-analyzer's result with rustc's shown expansion. Done means the stmt-to-block case parses and expands without the erroneous "expected Block" error, while the workaround's unnecessary trailing-semicolon warning is not required.
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