rust-lang / rust-lang/rust-analyzer
Type position macros invoked from another macro are not expanded in trait item autocompletion
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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