ISSUE DESCRIPTION Cannot complete macro path in macro <!-- Troubleshooting guide:…
- User
ISSUE DESCRIPTION
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.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /rust-analyzer, current file: none) bash-$
Assistant
I'll start by exploring the repository structure to understand the codebase and find the relevant code for macro path completion.
Assistant
I'll start by exploring the repository structure.
Assistant
Let me explore the repository structure further to understand the codebase.
Assistant
The issue is about macro path completion within a macro. Let me explore the
ide-completioncrate.Assistant
Let me look at how macro completion works. Let me search for relevant code.
Assistant
I need to make single tool calls. Let me search for macro completion code.
Assistant
Let me look at the context analysis to understand how completion context is determined for macro call arguments.
Assistant
Let me look at the macro expansion logic in analysis.rs more closely.
Assistant
Let me understand the issue better by creating a test that reproduces it. Let me look at how existing completion tests are structured.
Assistant
Let me look at the test
in_macro_expr_fragto understand the existing test structure for macro completions.Assistant
Let me look at how the
checkfunction works for completion tests.Assistant
Let me create a test to reproduce the issue.
Assistant
Let me create a temporary test to reproduce the issue.
Assistant
Let me add a test to the expression.rs test file temporarily and run it.
Assistant
Let me check if there's a rust-toolchain file or a specific nightly requirement.
Assistant
The test passed with an empty expectation, which confirms the issue - no completions are produced. Let me verify by printing the actual output.
Assistant
I need to add my module to the tests.rs. Let me add
mod expression_repro;aftermod expression;.Assistant
I need
completion_listto be a public function. Let me check its visibility.Assistant
I need to make
completion_listaccessible. Let me change my test file to usecrate::tests::completion_listinstead since it'spub(crate).Assistant
The actual completions are empty, confirming the issue. Now let me understand how the macro expansion-based completion works. Let me look at the expansion processing code.
Assistant
Let me look at the beginning of the analysis.rs to understand the main flow.
Assistant
Let me look at how
expand_and_analyzeis called and how the speculative file is built.Assistant
Let me add some debug tracing to understand what's happening during expansion.
Assistant
Let me add some debug eprintln to understand. Let me look at the
ttsvariable. Let me look at lines 256-379.Assistant
Let me add debug tracing to understand what's happening.
Assistant
The eprintln inside the match tuple caused a syntax issue. Let me fix it.
Assistant
The eprintln returns
()so it becomes(() , expand, speculative). The match arms expect(Option<...>, Option<...>). This is a type mismatch. Let me move the eprintln out of the match.Assistant
The
fake_ident_tokenis used later? Let me check if it's used after the match. Actually it was moved into the match. Let me check the rest of the function. It's only used in the speculative_expand call. But wait, the original code usedfake_ident_tokendirectly in the match tuple. Now I clone it. That should be fine. But isfake_ident_tokenused after? Let me check.Actually, in the original code,
fake_ident_tokenwas moved intospeculative_expand_macro_call. The function returns after this match. So cloning shouldn't be an issue. Let me compile.Assistant
There's still a compile error. Let me see the full error.
Assistant
Let me move the debug eprintln after
ttsis destructured.Assistant
The expansion succeeds but the recursion into
bar!()fails. Let me look atis_inside_macro_call.Assistant
Let me look at the
kind_macro_calland how NameRefKind is determined for macro call paths.Assistant
The expansion of
foo!(bar)succeeds, producingbar!(), and the cursor maps tobaron the macro path. But the recursion fails becauseis_inside_macro_callreturns true for the path token. Let me look at the git history of this check.Assistant
Let me look at the old
might_be_inside_macro_callimplementation before the rename.Assistant
Let me test a simpler scenario - macro path completion directly (without nesting).
Assistant
The direct macro path completion works (
bar$0!()), but the nested one (foo!(bar$0)) doesn't. This confirms the issue is in the expansion recursion. Let me check the other callers ofis_inside_macro_callto understand if I should change it directly or add a targeted fix.Assistant
I'll go with a targeted fix in
expand_maybe_stop. Let me first remove the debug eprintlns.Assistant
Now let me implement the fix. I'll modify the base case to also allow stopping when the token is on the path of a macro call.
Assistant
Now let me run the reproduction test to see if the fix works.
Assistant
The nested case now completes
barandfoomacros. The fix works. Let me test more edge cases.Assistant
All edge cases work correctly. Now let me run the full ide-completion test suite to make sure I didn't break anything.
Assistant
I still have the repro test in expression.rs. Let me remove that too.
Assistant
All 732 tests pass. Now let me add a proper test for this fix in the expression.rs test file, matching the existing conventions.
Assistant
Let me find the end of the
in_macro_expr_fragtest to add a new test after it.Assistant
The new test passes. Let me run the full ide-completion test suite once more to confirm nothing is broken.
Assistant
All 733 tests pass. Let me also run the broader
idecrate tests to ensure nothing in dependent crates breaks.Assistant
Let me also run the
ide-dbandide-ssrtests since they useis_inside_macro_callindirectly (though I didn't change that function).Assistant
All tests pass. Let me review the final changes.
Assistant
The changes look clean. Let me clean up temp files and do a final verification.
Assistant
Let me run the final full test suite to confirm everything passes.
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
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →