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:
macro_rules! bar { () => (); } macro_rules! foo { ($i:ident) => { $i!() }; } fn main() { foo!(bar$0); }Interface
No new interfaces are introduced.
- Assistant
Let me write a reproducing test first.
- Assistant
Now let me look at how
descend_into_macros_exactbehaves for safety, and checkis_inside_macro_callmore closely: - Assistant
Completions now appear, including
ma bar. Update the expectation: - Assistant
Now let me also verify the completion edit applies correctly to the original file, since the analysis happened inside an expansion:
- Assistant
Now run the broader test suites since
is_inside_macro_callis shared with search: - Assistant
All green. Run clippy on the touched crates:
- Assistant
The fix is complete. Summary of what was wrong and what I changed:
Problem
For
foo!(bar$0)wherefoo!expands its$i:identargument into a macro call$i!(), completion returned nothing. The completion analysis correctly expandedfoo!(bar)intobar!(), where the cursor tokenbaris the path of the inner macro call. At that point expansion can't (and shouldn't) go deeper — but the recursion base case inexpand_maybe_stop(crates/ide-completion/src/context/analysis.rs:151) rejects stopping if the token is "inside a macro call". returned for token with a ancestor — including the macro call's own path, which is not part of the macro's input. The whole expansion chain was therefore discarded, analysis fell back to the unexpanded token tree, and no completions were produced.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.