Fixing unused imports
Closed this issue · 3 comments
I really like rustfix
and expectations are more :)
cargo build
identifies unused imports. I would like to see rustfix
provides similar suggestion and remove these unused imports.
e.g.
warning: unused import: `std::io::prelude::*`
--> src/tiso/tiso_msg.rs:10:5
|
10 | use std::io::prelude::*;
| ^^^^^^^^^^^^^^^^^^^
warning: unused import: `std::fmt`
--> src/tiso/tiso_msg.rs:13:5
|
13 | use std::fmt;
| ^^^^^^^^
This should be fixed in rustc by creating an empty suggestion
Yeah, I've been missing that too! :)
The strategy is to suggest replacing the unused import with an empty string. If it is the only item in the use
(i.e., std::fs
in use std::fs;
is unused, in contrast to File
in use std::fs::{File, copy}
is unused), remove the whole use
statement.
This suggestion needs to be implemented in rustc, probably here.
I couldn't find an open issue there, you should open one! Feel free to copy this comment too if you like :) (Maybe mention rust-lang/rust#42823 as it tracks a few diagnostic things already.)
Edit: Damn you @oli-obk I'm writing a long comment here and you just waltz in and say the same thing! Again! :P
It would be good to remove unused crates extern crate xxx