Cannot complete macro path in macro <!-- Troubleshooting guide:…
- User
Cannot complete macro path in macro
rust-analyzer version: rust-analyzer 0.4.2897-standalone
rustc version: rustc 1.97.0-nightly (36ba2c771 2026-04-23)
editor or extension: Vim
code snippet to reproduce:
rustmacro_rules! bar { () => (); } macro_rules! foo { ($i:ident) => { $i!() }; } fn main() { foo!(bar$0); }Interface
No new interfaces are introduced.
- Assistant
Let me reproduce this with a test first.
- Assistant
ancestoris moved by the first cast; fix the borrow: - Assistant
The fix works — completions now appear. Update the test expectation:
- Assistant
All tests pass. Quick clippy check on the changed crates:
- Assistant
The clippy warning pre-exists on the clean tree — unrelated to my change. Final diff:
- Assistant
Fixed. Summary of the issue and fix:
Root cause
For
foo!(bar$0)wherefoo!expands$iinto$i!(), the completion machinery recursively expands macro calls. After the first expansion, the cursor tokenbarlands in the macro path position ofbar!():- The recursive
expandstep fails (correctly) — the actual pathbarand the speculative pathbar<marker>don't match, and the token has no ancestor.
- The recursive
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.