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:
rustmacro_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 first inspect the repository layout and search for macro/path completion code and existing completion fixtures. Then I’ll reproduce the missing completion with the project’s targeted test workflow before making a focused source change.
- Assistant
rgis unavailable in this environment, so I’ll usefindand recursivegrepto locate the completion crate and relevant tests without changing the repository. - Assistant
The expression completion tests already contain macro-metavariable scenarios near lines 1185 and 2640. I’ll inspect those fixtures, the completion dispatcher, and context construction to determine whether this is a syntax-context classification failure or macro expansion mapping failure.
- Assistant
The existing test proves completion through an
$identused as a normal expression/path, and another proves edit behavior when the expansion appends::bar; neither covers$i!(). I’ll temporarily add an exact regression test to the existing test module, run it to confirm the report, and remove that test before submission as required. - Assistant
The temporary reproducer is in place, but the environment has no rustup default configured. I’ll inspect the pinned Rust version and installed toolchains, then invoke Cargo with an available compatible toolchain (installing the pinned one only if necessary).
- Assistant
No compiler is installed. The repository pins a Rust commit, so I’ll ask rustup to install exactly that toolchain; this is an environment setup step and does not alter tracked repository files.
- Assistant
Standard rustup does not accept commit hashes as channel names. I’ll inspect repository setup documentation and available helper binaries for the project’s expected commit-toolchain installation method, while also checking the pinned commit’s likely release era from lockfile metadata.
- Assistant
CI uses
rustup-toolchain-install-master, but installing that helper itself needs Cargo. I’ll bootstrap a minimal current nightly through rustup first, use its Cargo to install the CI-pinned helper, and then install the exact compiler commit. - Assistant
Nightly installed successfully, but the chained helper installation failed because this container’s rustup home/shim layout makes Cargo’s rustup discovery fail. Since the installed nightly is only a few months newer than the pin and should compile the code, I’ll run the reproducer directly with the concrete toolchain Cargo binary, bypassing shims and the unnecessary exact-toolchain step.
- Assistant
The build progressed, but repository build scripts/toolchain wrappers automatically installed and mixed stable/1.65 artifacts into the same target directory, causing incompatible metadata. I’ll inspect Cargo configuration and environment to understand those wrappers, then clean only generated build artifacts and rerun under the repository’s selected toolchain consistently.
- Assistant
The default remains nightly, so the stable compiler likely came from a nested
rust-toolchainfile encountered while compiling a vendored/tool dependency, and direct Cargo still resolvesrustcthrough PATH. I’ll locate all toolchain override files and then forceRUSTCto the concrete nightly binary for a clean, consistent build. - Assistant
Cargo normalized
$HOMEunexpectedly to/in theRUSTCvalue, even though shell tilde resolution used/rootearlier. I’ll avoid environment ambiguity by supplying absolute/root/.rustup/...paths and rerun after the already-completed clean. - Assistant
The exact reproducer fails with no
barcompletion (check_editcannot find the item), confirming the issue on current code. I’ll now trace how completion creates a speculative macro expansion and identifies the caret token, focusing on differences between a metavariable expanded as a path and as a macro call. - Assistant
The likely fault is in recursive expansion selection:
$i!()expands into a nested macro call whose name is the speculative marker and therefore cannot resolve, while the algorithm treats one-sided expansion failure as an inconsistent state. I’ll inspect that branch and the top-level analysis fallback precisely before changing behavior. - Assistant
The control flow confirms the problem: after
foo!expands, recursion sees actualbar!()versus speculativebarraCompletionMarker!(), rejects the differing macro paths, and refuses to stop because the caret is “inside a macro call.” For a caret in the macro call’s own path, however, that is exactly the final context to classify; only carets in its arguments should recurse. I’ll inspectexpand_and_analyzeinitialization and semantic macro-call predicates to implement that distinction at the stop boundary rather than weakening general consistency checks. - Assistant
I’ll inspect
is_inside_macro_callto ensure any new syntactic path check complements rather than duplicates semantic behavior, then patchexpand_maybe_stopso it returns the current expansion when the mapped speculative token lies in a macro call path. This keeps recursive expansion for macro arguments unchanged. - Assistant
The semantic predicate intentionally treats both path and arguments as “inside,” so a narrower syntax check is needed. I’ll add a small local condition using the nearest
ast::MacroCalland path-range containment, returning a normalExpansionResultbefore trying to resolve/expand that call. Then I’ll rerun the exact reproducer. - Assistant
The exact regression now passes. The guard is deliberately limited to the mapped token’s macro path, so nested macro arguments still expand recursively; it also naturally supports qualified macro paths because containment covers the whole path. I’ll remove the temporary test fixture (tests must not be submitted), format the changed source, inspect the diff, and run the completion crate’s full test suite.
- Assistant
All 732
ide-completiontests pass. Formatting was the only skipped substep because rustfmt was not installed; I’ll install that toolchain component, run rustfmt, then rerun the targeted macro-related tests and verify the final working tree contains only the source fix with no temporary test changes or generated files.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.