Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macro calls emitting macro definitions resolve badly #14862

Open
Veykril opened this issue May 20, 2023 · 1 comment · Fixed by rust-lang/rust#111810
Open

macro calls emitting macro definitions resolve badly #14862

Veykril opened this issue May 20, 2023 · 1 comment · Fixed by rust-lang/rust#111810
Labels
A-macro macro expansion C-bug Category: bug

Comments

@Veykril
Copy link
Member

Veykril commented May 20, 2023

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 Veykril added A-macro macro expansion Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug labels May 20, 2023
@Veykril
Copy link
Member Author

Veykril commented May 20, 2023

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.

@Veykril Veykril self-assigned this May 20, 2023
@Veykril Veykril removed their assignment May 21, 2023
@Veykril Veykril reopened this May 22, 2023
@Veykril Veykril removed the Broken Window Bugs / technical debt to be addressed immediately label May 22, 2023
@Veykril Veykril changed the title Core library marker impls for primitives no longer resolve correctly due to macro call emitting macro definitions macro calls emitting macro definitions resolve badly May 22, 2023
thomcc pushed a commit to tcdi/postgrestd that referenced this issue Jul 18, 2023
Don't use inner macro in `marker_impls`

Just recurse instead of having to define an inner macro to avoid the problem with expansion binders being misnumbered between the `$meta` and `$T` variables.

cc `@Veykril` this should fix rust-lang/rust-analyzer#14862 since we've gotten rid of the inner macro.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant