-
Notifications
You must be signed in to change notification settings - Fork 14.1k
resolve: Preserve ambiguous glob reexports in crate metadata #147984
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
base: main
Are you sure you want to change the base?
Conversation
|
rustbot has assigned @jdonszelmann. Use |
|
@bors try |
resolve: Preserve ambiguous glob reexports in crate metadata
This comment has been minimized.
This comment has been minimized.
|
@craterbot check |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🎉 Experiment
Footnotes
|
|
That's a lot of breakage. |
aa2fb6e to
e388d62
Compare
This comment has been minimized.
This comment has been minimized.
|
@bors try
|
This comment has been minimized.
This comment has been minimized.
resolve: Preserve ambiguous glob reexports in crate metadata
|
@craterbot run mode=check-only p=1 crates=https://crater-reports.s3.amazonaws.com/pr-147984/retry-regressed-list.txt |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
| //~^ ERROR `C` is ambiguous | ||
| //~| ERROR `C` is ambiguous | ||
| //~| WARN this was previously accepted | ||
| //~| WARN this was previously accepted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does this emit so many duplicate warnings? It looks like theres two unique ones, the one for the local ambiguity and the one for the external ambiguity, but the stderr file looks like its emitting each of those twice for a total of four warnings. Why isn't this being prevented by the warning deduplication logic?
rust/compiler/rustc_resolve/src/lib.rs
Lines 2072 to 2075 in 743dc68
| if !self.matches_previous_ambiguity_error(&ambiguity_error) { | |
| // avoid duplicated span information to be emit out | |
| self.ambiguity_errors.push(ambiguity_error); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn record_use_inner walks the import chain and reports an ambiguity at every step.
I think we could only report the first one (if it's an error).
I look at the PR introducing the deduplication logic, and I don't think the author really understood what they were doing, not sure why it doesn't deduplicate this specific case.
In any case, probably off-topic for this PR.
Upd: also record_use can run twice on the same "use", at least for imports (for other diagnostic reasons).
| // First, should this ambiguous item be omitted considering the maximum visibility | ||
| // of `issue_114682_2_extern::m::max` in the type namespace is only within the extern crate. | ||
| // Second, if we retain the ambiguous item of the extern crate, should it be treated | ||
| // as an ambiguous item within the local crate for the same reasoning? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you link to where the decision on these questions was made?
From my understanding of the PR it's looking like you went with
- no
- no
Is that right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Correct, seems to be the simplest and conservative choice.
- I don't quite understand the sentence, but it seems like the answer is "yes", because
issue_114682_2_extern::maxis indeed treated as ambiguous in this test (= local crate).
| a.ext(); | ||
| //^ FIXME: it should report `ext` not found because `SettingsExt` | ||
| // is an ambiguous item in `issue-114682-3-extern.rs`. | ||
| //~^ ERROR no method named `ext` found for type `u8` in the current scope |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've not yet looked into how ambiguous imports interact with which traits are in scope so the logic for this is unfamiliar to me but I find this behavior surprising. I would have expected this to report an ambiguity error while selecting the innermost1 candidate and continuing, not for it to block the selection of all three candidates in scope with no mention of ambiguity.
This doesn't seem like an ideal diagnostic experience. Is there some structural issue that makes it hard to identify and report that this error was caused by an interaction with ambiguious imports?
Footnotes
-
I know this is a globvsglob/globvsexpanded issue where they're ambiguous within a single scope so I'm not sure innermost is accurate, but I don't remember off hand how the candidates for this kind of ambiguity are stored and its nearing the end of the day so I wanna get my first review pass posted rather than diving in more deeply. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this PR and that PR combined will result in .ext() producing a compatibility warning about the method call being ambiguous.
@petrochenkov am I correct in understanding that https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#ambiguous-glob-reexports represents the def-site lint but not the second suggestion from niko quoted above? @tmandry am I correct in assuming that lang doesn't consider adding the second lint you mentioned to be a blocker for this PR? |
|
@yaahc Just checking you mean this one. Correct, I don't consider it a blocker.
|
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
743dc68 to
255f6c3
Compare
This comment has been minimized.
This comment has been minimized.
|
@rustbot ready |
This comment was marked as resolved.
This comment was marked as resolved.
| = note: ambiguous because of multiple glob imports of a name in the same module | ||
| note: `mac` could refer to the macro defined here | ||
| --> $DIR/auxiliary/glob-vs-expanded.rs:18:9 | ||
| | | ||
| LL | pub use m::*; | ||
| | ^ | ||
| note: `mac` could also refer to the macro defined here | ||
| --> $DIR/auxiliary/glob-vs-expanded.rs:18:9 | ||
| | | ||
| LL | pub use m::*; | ||
| | ^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be emitting the diagnostic as though it were a globvsglob rather than a globvsexpanded ambiguity.
I would expect it to say:
= note: ambiguous because of a conflict between a name from a glob import and a macro-expanded name in the same module during import or macro resolution
note: `mac` could refer to the macro imported here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the unnecessary glob reexport from the test for now.
The root issue here is sort of hard to fix, for that you need https://github.com/petrochenkov/rust/tree/neverwrite, but it is mostly blocked on #149195.
|
go ahead and r=me once the issue with the diagnostic on the globvsexpanded test is corrected. |
|
@rustbot author |
So in cross-crate scenarios they can work in the same way as in crate-local scenarios.
255f6c3 to
51780a5
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@bors r=yaahc |
resolve: Preserve ambiguous glob reexports in crate metadata So in cross-crate scenarios they can work in the same way as in crate-local scenarios. Change Description: #147984 (comment) Resurrection of #114682. One of unblocking steps for #145108. Fixes #36837.
So in cross-crate scenarios they can work in the same way as in crate-local scenarios.
Change Description: #147984 (comment)
Resurrection of #114682.
One of unblocking steps for #145108.
Fixes #36837.