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
Now let me reproduce the issue with a test. Let me look at how existing macro-input completion tests are structured:
- Assistant
Now let me write a failing test to confirm the bug. I'll add it near the other macro-input tests in
expression.rs: - Assistant
Completions now appear —
barandfooare offered as macros (rendered without!(…)since the bang already exists in the expansion). Let me update the expectation: - Assistant
Now run the broader test suites to check for regressions —
ide-completionfully, plushir,ide-db, andide(which exercisesearch.rs): - Assistant
The clippy warning pre-exists on the clean tree — not introduced by this change. Here's the final state of the fix and test:
- Assistant
Fixed. Here's a summary of the issue and the resolution:
Root cause
Completing
foo!(bar$0)wherefoo!expands$i:identinto$i!()failed with no completions at all. The trace:- Completion recursively expands the macro call:
foo!(bar)→bar!(), and the cursor tokenbarmaps to the macro path ofbar!()in the expansion. - In the expansion,
barhas noTokenTreeancestor (it's in the path, not the input), soexpand()incrates/ide-completion/src/context/analysis.rscan't recurse further and returnsNone. - The recursion base case at
analysis.rs:153then asksSemantics::is_inside_macro_callto decide whether it's safe to stop and analyze here. Despite its doc comment ("we strictly check if it lies inside the input of a macro call"), the implementation returnedtruefor any token under aMacroCallnode — including the path tokenbarofbar!(). - That
trueaborted the whole expansion chain, and the fallback analysis of the raw, unexpanded token tree yielded nothing.
Fix
crates/hir/src/semantics.rs:1090—is_inside_macro_callnow only counts aMacroCallancestor when the token actually lies within its token tree, matching the documented contract. Nested cases (e.g. a path token of an inner call sitting inside an outer call's token tree) still returntruevia the outer ancestor.With the fix, the base case triggers on the expanded
bar$0!()and completion correctly offers macros (ma bar,ma foo) plus the usual expression-position items — the same list you'd get typingbar$0!()directly.Verification
- New snapshot test
in_macro_path_fragincrates/ide-completion/src/tests/expression.rs(failed with empty output before the fix) cargo test -p ide-completion— 733 passedcargo test -p hir -p ide-db -p ide(covers the otheris_inside_macro_callcaller insearch.rs) — all passed- Clippy on touched crates: no new warnings (the one reported warning pre-exists on the clean tree)
- Completion recursively expands the macro call:
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 →
- 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 →