How to disable the warning "unused import" instead of using #[allow(unused)] all the time?

Hi there!
well, i had a problem of the warning about unused crates/imports or even variables, i want to disable all of them, since i'm just learning, and sometimes i don't need to use them at that time, nd i don't wanna delete them, so, how can i avoid that warning?
thank you all ^^

Delete the import? :slight_smile:

1 Like

one trick is use #![allow(unused)] at the top of the file. Notice the exclamation point. This will disable the warning for the entire file instead of having to add the attribute for every usage.

1 Like

Doing that will disable it for the entire module, as well as all its submodules.

Lints (that is, warnings) can now (finally) be configured project-wide in Cargo.toml. Just add this to your Cargo.toml:

[lints.rust]
unused_imports = "allow"

Another way is to add the following to your Cargo config:

[build]
rustflags = "-Aunused_imports"

which makes cargo to always pass the above parameter to the compiler, [A]llowing the lint.

4 Likes

thank you so much man ! sorry for the dely to repo ^^

i said i don't wanna delete them, because i'll need them later

thanks mate! really usefull, have a nice day !

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.