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
Investigating macro path completion in rust-analyzer for this bug report.
- Assistant
Let me reproduce the issue with a test and trace how completion handles macro paths inside macro arguments.
- Assistant
Confirmed: no completions. Tracing how macro expansion and path completion interact for this case.
- Assistant
Top-level macro path completion works; nested expansion fails in
expand_maybe_stop. Implementing the fix. - Assistant
Completions work. Updating test expectations and removing the debug test.
- Assistant
Fixed macro path completion inside macro expansions.
Problem
For code like:
rustmacro_rules! bar { () => (); } macro_rules! foo { ($i:ident) => { $i!() }; } fn main() { foo!(bar$0); }rust-analyzer expands
foo!to{ bar!() }and should offer macro completions at thebarpath. Instead it returned nothing.Root cause
During speculative macro expansion, completion stops when it can’t expand further and the cursor is inside a macro call. That’s correct for macro arguments (e.g.
foo!($0)), but wrong for macro paths (e.g.barinbar!()).After
foo!expanded to{ bar!() }, the cursor mapped to thebarinbar!(). That position is inside a , so returned instead of treating it as a completable macro path.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.