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); }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 trace macro completion handling and its tests, reproduce the completion behavior if practical, then make the smallest source change and run targeted tests. I’ll also verify the resulting diff and explicitly address each checklist item before submission.
- Assistant
The repository lacks
rg, so I’ll usegrep/findinstead. I’m narrowing this to completion logic around macro invocations and token joining, since the cursor is between a macro name and!. - Assistant
The failure is in recursive macro expansion: for
foo!(bar$0), the outerfooexpands, but the speculative expansion containsbar<completion-marker>!while the real expansion containsbar!. The current mismatch aborts expansion entirely, losing the mapped context wherebarcan be resolved. I’ll preserve the current real/speculative pair when that mismatch is specifically caused by the completion marker in the macro path, so normal unrelated mismatches retain existing behavior. - Assistant
The source change is applied, but tests cannot start because this environment has no configured Rust toolchain (
rustupreports no default). I’ll still perform static checks of the change, inspect repository conventions/toolchain metadata, and use any directly available toolchain if present. - Assistant
A Rust 1.96 toolchain is installed but not selected by rustup, so I’ll invoke its cargo explicitly for the targeted crate test. This may expose only version incompatibility with the checkout; regardless, I’ll report that distinctly from the earlier environment-selection failure.
- Assistant
The explicit toolchain reached compilation and found one type issue:
SyntaxTextdoes not providecontainsdirectly (unlike token text). I’ll convert it to a string for the marker check, then rerun the targeted test. - Assistant
The targeted macro renderer tests pass (6/6), and formatting/checks now pass after correcting the
SyntaxTextconversion. I’ll run the fullide-completionlibrary test suite to catch regressions in expansion and completion behavior, then inspect the final status. - Assistant
The full
ide-completionlibrary suite passes: 732 tests, 0 failures. The fix is limited to preserving expansion context for marker-induced macro-path mismatches; unrelated mismatches still returnNoneas before. I’ll do the final diff/status check and submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.