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 — I'll search the codebase for how completions are handled in macro contexts.
- Assistant
I'll add a test for this scenario and run it to see what completions we get today.
- Assistant
No completions returned — I'll trace speculative macro expansion and path-context detection.
- Assistant
Macro path tokens are incorrectly treated as macro input because
is_inside_macro_callmatches any token underMacroCall, including the callee path. I'll narrow that check to tokens inside the macro's token tree. - Assistant
Fixed macro path completion when an
identmetavariable expands to a macro invocation like$i!().Root cause
Completion uses speculative macro expansion to map the cursor from
foo!(bar)to the expanded positionbar!(). Expansion stopped too early becauseis_inside_macro_calltreated any token under aMacroCallas macro input—including the callee path (barinbar!()).That made
expand_maybe_stopthink it was still inside macro input and fail to reach the macro-path completion context, so no completions were offered.Fix
Updated
is_inside_macro_callincrates/hir/src/semantics.rsto only return true for tokens inside the macro call's token tree (the actual input), not the path:pub fn is_inside_macro_call(&self, token @ InFile { value, .. }: InFile<&SyntaxToken>) -> bool { value.parent_ancestors().any(|ancestor| { if let Some(macro_call) = ast::MacroCall::cast(ancestor.clone()) { return macro_call .token_tree() .is_some_and(|tt| tt.syntax().text_range().contains_range(value.text_range())); }This matches the documented behavior (“strictly check if it lies inside the input of a macro call”).
Tests
Added
completes_macro_path_in_macro_invocationcovering both partial typing (foo!(bar$0)) and applying a completion from scratch (foo!($0)).All 733
ide-completiontests pass.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →
- fable-5Compare side by side →