-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
FCW Lint when using an ambiguously glob imported trait #149058
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
This comment has been minimized.
This comment has been minimized.
|
Addressed your comments and updated pr title and description. @rustbot ready |
| self.tcx.node_lint(AMBIGUOUS_TRAIT_GLOB_IMPORTS, segment.hir_id, |diag| { | ||
| diag.primary_message(format!("Use of ambiguously glob imported trait `{trait_name}`")) | ||
| .span(segment.ident.span) | ||
| .span_label(import_span, format!("`{trait_name}`imported ambiguously here")) | ||
| .help(format!("Import `{trait_name}` explicitly")); | ||
| }); |
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.
Is it possible to add some kind of suggestion like:
Consider importing `{trait_name}` directly:
+ use m1::{trait_name};
|
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
r? @lcnr or someone else from types for the method resolution part. This will need to go through crater and then lang team after the review. |
|
☔ The latest upstream changes made this pull request unmergeable. Please resolve the merge conflicts. |
|
☔ The latest upstream changes (presumably #150729) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Thanks for the change description @LorrensP-2158466. This makes sense to me, with the understanding that the desired end state is to allow the imports, but error on any use of the ambiguously imported traits. @rfcbot fcp merge lang |
|
Team member @tmandry has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
|
Sounds right to me. @rfcbot reviewed |
|
@rfcbot reviewed This looks right! |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
|
@LorrensP-2158466 Looking over your examples, I want to verify that the case of redundant glob imports of the same trait will not produce an FCW (and will not be broken when we make the change the FCW is paving the way for). In other words, if you have two modules that do Could you confirm that, and could you confirm that there's a test added to verify that? (And if not, could you please add one?) |
|
@joshtriplett This can't happen, we only report a lint if that Trait is ambiguous. Importing the same thing is not seen as an ambiguity, so no lint will be reported if that trait is used. for example, to make sure I understand your question: mod t {
pub trait Trait {
fn method(&self) {}
}
impl Trait for i8 {}
}
mod m1 {
pub use t::Trait;
}
mod m2 {
pub use t::Trait;
}
use m1::*; // glob imports `t::Trait`
use m2::*; // glob imports `t::Trait` as well, it's the exact same item so there is no ambiguity.
fn main() {
0i8.method(); // no ambiguous trait used so no FCW lint
}The current tests do not check this as we're testing ambiguities. I'll add this test as you requested. |
dfbd632 to
024b5a8
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. |
|
Also rebased because of the conflict (and being 1400 commits behind...). |
Related to #147992.
Report a lint when using an ambiguously glob import trait, this is a FCW because this should not be allowed.
r? @petrochenkov