rust-lang / rust-lang/rust-analyzer
rust-analyzer macro expansion does not implement opaque ASTs
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
rust-analyzer version: (rust-analyzer version: 0.4.1888-standalone (6fce1d71d 2024-03-19)
rustc version: rustc 1.79.0-nightly (a7e4de13c 2024-03-19)
This was tested against a matrix of latest stable and nightly rustc, and stable and nightly rust-analyzer.
code snippet to reproduce:
macro_rules! a {
($arg:ident:Option<$type:ty>) => {
"a"
};
($arg:ident:$type:ty) => {
"b"
};
}
macro_rules! b {
($arg:ident:$type:ty) => {
a!($arg:$type)
}
}
a!(a:i32); // "b"
a!(a:Option<i32>); // "a"
b!(a:i32); // "b" in both rustc and rust-analyzer
b!(a:Option<i32>); // "b" in rustc, "a" in rust-analyzer
There is a discrepancy between the behavior of rustc and rust-analyzer when expanding this macro. I personally believe that the rust-analyzer behavior is more correct but it is up to rustc to decide this. Macro a works as expected for simple usage but when the input is passed indirectly through another macro this difference occurs. Opaqueness does not seem to be enforced in rust analyzer.
I also submitted a rustc issue: rust-lang/rust#122774
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 macro expansion discrepancy with the Rust snippet and the listed rustc and rust-analyzer versions. Trace rust-analyzer's handling of forwarded macro fragments and opaque ASTs, then compare it with rustc's behavior and the macros-by-example forwarding rule. Done means indirect expansion follows the intended opaqueness behavior consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100