rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.2k stars 1.6k forks source link

macro calls emitting macro definitions resolve badly #14862

Open Veykril opened 1 year ago

Veykril commented 1 year ago

Edit: Core no longer relies on this, the bug itself is still a thing though The core library unfortunately started using the weird macro pattern where a macro invocation produces a textually scoped macro that is immediately invoked again. This works fine for r-a if the macro is only used once in a given scope, but the core library uses it several times. All consecutive uses of the inner produced macro unfortunately resolve to the very first one, meaning all impls produced by this macro end up being for StructuralEq. https://github.com/rust-lang/rust/blob/77fb0cd3aa276919e00397f526616c5036562ea1/library/core/src/marker.rs#L44C1-L67

Veykril commented 1 year ago

I thought we had an issue for this already but I guess not? Basically when we have multiple macros in textual scope on the item level we fail to resolve them properly in general iirc because we don't track when they shadow each other. This is basically what's happening here, so all invocations resolve to the first macro. I looked into that a year ago but couldn't come up with a solution at the time, it's a difficult problem to solve.