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 add a test reproducing the issue and confirm it fails:
- Assistant
Completions now appear. Let me update the expectation and review it:
- Assistant
All tests pass. Let me run clippy on the touched crates:
- Assistant
The clippy warning is pre-existing on the clean tree, unrelated to this change. Here's the final diff:
- Assistant
Fixed. Summary of what was wrong and the fix:
Root cause
For
foo!(bar$0)wherefoo!expands$i:identinto$i!(), completion recursively expands macros to find the completion position. After expandingfoo!, the completion tokenbarlands as the path of the macro callbar!()in the expansion:expand()incrates/ide-completion/src/context/analysis.rscouldn't descend further — the token has noTokenTreeancestor (it's the call path, not macro input), so it returned .
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.