Often during development, I have a bunch of unused imports and variables. I like to fix those after I have correctly working code. The warnings these generate cause me to scroll though the cargo build
output to find errors among all the warnings.
Is that possible to only show the warnings if compilation succeeds?
I don't want to ignore the warnings entirely, since I do want to solve them before committing the code.
You can suppress warnings in your compilation using the -Awarnings
flags. If you use Cargo, you can add it with:
cargo rustc -- -Awarnings
That will compile your crate with warnings disabled, so only errors will show up. When you get a successful compilation, you can switch back to:
cargo build
And your crate will compile again (because the flags have changed, the target is no longer up to date) and you will get the detailed warnings.
You can try automating them by running:
cargo rustc -- -Awarnings && cargo build
This has the drawback of compiling the crate twice if there are no errors and that can take some extra time.
If you want to compile all the dependencies without the warnings, you can run instead:
RUSTFLAGS=-Awarnings cargo build
But then, the double compilation issue is quite more relevant.
As as side note, I think that some IDEs (VSCode?) are able to do that: sort the compiler messages and filter out the ones you are not interested in.
You're looking for:
cargo install cargo-limit; cargo lcheck
See https://github.com/alopatindev/cargo-limit/blob/master/README.md for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With