rust-lang / rust-lang/rust-analyzer

Type position macros invoked from another macro are not expanded in trait item autocompletion

Open
#22,642 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-assists A-completion C-feature
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

I have a simple macro that selects between two types, depending on the presence of the second type. When using autocomplete to implement trait methods the inner macro invocations are not expanded. Maybe this is desirable in some situations, but in this one it actually results in a worse experience. Maybe a rust analyzer attribute on macros can control whether to expand the macro when in type position?

rust-analyzer version: rust-analyzer version: 0.3.2845-standalone

rustc version: rustc 1.96.0-nightly (20f19f461 2026-03-21)

editor or extension: VSCode

relevant settings: N/A

repository link (if public, optional): N/A

code snippet to reproduce:

macro_rules! foobar {
  ($name:ident, $A:ty $(, $B:ty)?) => {
    trait $name {
      fn foo(v: foobar!(@ $A $(, $B)?));
    }
  };
  (@ $A:ty, $B:ty) => { $B };
  (@ $A:ty) => { $A };
}

foobar! {
  Hello, u32
}

impl Hello for () {
  fn foo(v: foobar!(@u32)) {
    // :( pls expand
  }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the supplied Rust macro example in VSCode with rust-analyzer and inspect the trait-item autocompletion path for type-position macro expansion. Done means the inner foobar! type invocation expands during completion and the expected trait method parameter is recognized.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.