rust-lang / rust-lang/rust-analyzer
"expected punct: `,`" error for macro_rules macro that compiles with rustc
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: 0.4.2625-standalone
rustc version: 1.90.0 (1159e78c4 2025-09-14)
editor or extension: vscode, pre-release (0.4.2625)
repository link: https://github.com/jni-rs/jni-rs/tree/rust-analyzer-macro-expected-punct-bug
I've been working on a define_reference_type! macro_rules macro for the jni crate which is building and working as expected when built with cargo+rustc but I'm finding that it's not practical to use while rust-analyzer hits these "expected punct: `,`" errors and then I also can't use rust-analyzer to expand the macro for debugging.
In the linked jni branch there is an standalone version of the macro under examples/test-macro-parser.rs where the majority of the macro is identical to the real one that fails but the final step that generates the jni-specific code is stubbed for testing. Since this doesn't trigger rust-analyzer issues that seems to suggest that the issue is related to the final 'gen' step in the macro.
In the linked branch i've tried stripping out a bunch of the gen/emit code in the real macro too such that it still compiles but also still triggers the rust-analyzer error.
In vscode the error can be seen in any of the src/objects/jfoo.rs files that use the define_reference_type macro. Such as src/objects/jthrowable.rs where I've also tried stubbing out a more minimal invocation of the macro in an attempt to simplify the reproduction.
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
Reproduce the issue from the linked jni branch, starting with examples/test-macro-parser.rs and the macro in src/refs/macros.rs. Compare the failing invocations in src/objects/jthrowable.rs with the standalone macro and inspect the reported expected punct: ,`` diagnostics. Done means the valid macro compiles without false diagnostics and rust-analyzer can expand it for debugging.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100