Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I only show warnings if there are no errors?

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.

like image 209
Mark Avatar asked Nov 17 '18 20:11

Mark


2 Answers

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.

like image 97
rodrigo Avatar answered Oct 13 '22 21:10

rodrigo


You're looking for:

cargo install cargo-limit; cargo lcheck

See https://github.com/alopatindev/cargo-limit/blob/master/README.md for more information.

like image 25
Hezuikn Avatar answered Oct 13 '22 22:10

Hezuikn