-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Feature request: warn about redundant imports #5416
Comments
I would like to tackle this one, but I'm not sure about the interactions with the existing I guess it would be coherent to only trigger this lint for |
An overlap of these lints shouldn't matter that much, since |
Someone correct me if I'm wrong, but I think this is not doable currently due to If there is a non-glob import introducing the name, that seems to get precedence, and there is no way to know from the lint if the glob also could have introduced that same name. |
Is this a problem though? if there is an import |
It seems to be the latter (does not get returned if there is a non-glob import). With this code... use std::io::prelude::*;
use std::io::Write;
struct S {}
impl Write for S {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
Ok(42)
}
fn flush(&mut self) -> std::io::Result<()> {
Ok(())
}
} Adding a cx.tcx.names_imported_by_glob_use(item.hir_id.owner.to_def_id()); I get:
If I comment out the non-glob import, I get:
|
Or yeah, in that case, this is really limited/hard to implement. |
I feel then this is a bit out of my league for now, I will leave it so someone else can address it. |
I believe this is already implemented.
results in:
What is missing is the ability to automatically |
This is implemented as a lint in the compiler now, so there's nothing that can be done from the clippy side at this point. |
Closing, since this doesn't really seem actionable in clippy anymore (see #5416 (comment) and #5416 (comment)), all the reproducers listed here are covered by |
For example
Should give a warning, because
drop
is in thestd
prelude and it's already in scope.Should also give a warning, because
Write
is inio
's prelude and is already imported.The text was updated successfully, but these errors were encountered: