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

derive breaks "ambiguous name" diagnostic if there is a level of indirection #81887

Closed
pr2502 opened this issue Feb 8, 2021 · 3 comments
Closed
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pr2502
Copy link
Contributor

pr2502 commented Feb 8, 2021

Hello. I've noticed a strange behaviour where rust-analyzer and rustc would disagree what was wrong with my code. Turns out neither of them were right, I've had an "ambiguous name" problem however both rustc and rust-analyzer resolved the type anyway and they chose a different type to disambiguate into.

I've managed to make this minimal reproduction.
I can either remove the derives or remove the indirection through the c module and the problem will go away.

I expected to get a "Foo is ambiguous" error, instead i get an error for one of the usages of Foo which doesn't match the resolved type of Foo.

As a side-note, at least for rustc the resolved type seems to be dependent on the lexical order of the module/type definitions (not reexports), if that helps at all.

I get the same result on both nightly and stable, locally and on the playground. I found these issues #56593 and #62769 which sound similar but the problem there seems to be the opposite - "type doesn't resolve when it should" (in the presence of derive) instead of here "type resolves when it shouldn't".

@pr2502 pr2502 added the C-bug Category: This is a bug. label Feb 8, 2021
@pr2502 pr2502 changed the title derive breaks "ambiguous name" lint if there is a level of indirection derive breaks "ambiguous name" diagnostic if there is a level of indirection Feb 8, 2021
@estebank estebank added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 10, 2021
@estebank
Copy link
Contributor

A quick check in godbolt seems to show that this is not a regression.

CC @petrochenkov who might be interested in this.

@estebank estebank added the D-confusing Diagnostics: Confusing error or lint that should be reworked. label Feb 11, 2021
@petrochenkov
Copy link
Contributor

This looks like a same issue as #56593 linked above, or at least it has the same underlying reasons.
Glob imports from a module are not always properly updated when a macro is expanded in that module.

@estebank
Copy link
Contributor

Closing as duplicate, copying the text to a comment on the other thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants