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
Investigating macro path completion inside macro invocations — searching the codebase for how completion handles
$identfragments and macro paths. - Assistant
Running a completion test with the reported snippet to reproduce the issue.
- Assistant
The test reproduces the bug — no completions. Tracing how speculative expansion classifies the context.
- Assistant
Implementing the fix:
expand_maybe_stopshould stop when the cursor is on a macro call path, not only when outside macro calls. - Assistant
The nested
bar!()is fully expanded in the actual expansion ({ () }), so we should check the speculative file for macro-path position instead. - Assistant
Macro path completion works; filtering expr completions when
has_macro_bangis true and cleaning up debug code. - Assistant
Fixed macro path completion inside macro arguments for patterns like
$i:ident => { $i!() }.Root cause
When completing inside
foo!(bar$0)wherefooexpands to$i!(), rust-analyzer speculatively expands the outer macro to learn that the cursor is at a macro path. Two things blocked that:-
Expansion stopping too early — After speculative expansion produced
barraCompletionMarker!(), the recursive expander tried to expand that inner macro call. When that failed, it refused to stop because the token was still “inside a macro call.” The actual expansion ({ () }) had already expanded the nestedbar!(), so the macro-path position only existed in the speculative file. -
No macro-only filtering — Even when the macro-path context was detected (
has_macro_bang = true), expression completions (keywords, functions, etc.) were still offered alongside macros.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.