Skip to content
TheChatArchiveThe Chat Archive
fable-5· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

Cannot complete macro path in macro <!-- Troubleshooting guide:…

  1. 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.

  2. Assistant

    Now let me reproduce the issue with a test. Let me look at how existing macro-input completion tests are structured:

  3. 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:

  4. Assistant

    Completions now appear — bar and foo are offered as macros (rendered without !(…) since the bang already exists in the expansion). Let me update the expectation:

  5. Assistant

    Now run the broader test suites to check for regressions — ide-completion fully, plus hir, ide-db, and ide (which exercise search.rs):

  6. 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:

  7. Assistant

    Fixed. Here's a summary of the issue and the resolution:

    Root cause

    Completing foo!(bar$0) where foo! expands $i:ident into $i!() failed with no completions at all. The trace:

    1. Completion recursively expands the macro call: foo!(bar) → bar!(), and the cursor token bar maps to the macro path of bar!() in the expansion.
    2. In the expansion, bar has no TokenTree ancestor (it's in the path, not the input), so expand() in crates/ide-completion/src/context/analysis.rs can't recurse further and returns None.
    3. The recursion base case at analysis.rs:153 then asks Semantics::is_inside_macro_call to 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 returned true for any token under a MacroCall node — including the path token bar of bar!().
    4. That true aborted 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_call now only counts a MacroCall ancestor 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 return true via 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 typing bar$0!() directly.

    Verification

    • New snapshot test in_macro_path_frag in crates/ide-completion/src/tests/expression.rs (failed with empty output before the fix)
    • cargo test -p ide-completion — 733 passed
    • cargo test -p hir -p ide-db -p ide (covers the other is_inside_macro_call caller in search.rs) — all passed
    • Clippy on touched crates: no new warnings (the one reported warning pre-exists on the clean tree)

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.