Is it possible to invoke cargo build
, cargo test
, cargo bench
, etc with a flag that instructs warnings to be suppressed (e.g., cargo build --no-warnings
)? The warnings are great, and I don't want to suppress them indefinitely (e.g., using code annotations), but having a long spew of warnings when I'm trying to run a benchmark gets in the way and makes it a pain to scroll back and compare benchmarks against one another.
You could set RUSTFLAGS=-Awarnings
to allow all. But it's a little inconvenient because any change to RUSTFLAGS
causes everything to rebuild.
Ah gotcha. Well better than nothing; thanks!
Would cargo rustc
work in this case? That's the difference between it and
RUSTFLAGs; it doesn't apply the flags to all crates, only the current crate.
I'm not sure what you mean - as in, invoking it as RUSTFLAGS=-Awarnings cargo rustc
as opposed to RUSTFLAGS=-Awarnings cargo build
?
I think cargo prints warnings to stderr; so on linux, I've been able to do, e.g.
cargo test 2>/dev/null
to redirect stderr, and that seems to work (shows only the results, not the warnings).
Redirecting to /dev/null
is certainly an option if you know there are no errors, but otherwise won't it redirect errors as well?
Yeah, it does hide the errors.
EDIT: If you mean failed test results, those are printed to stdout and still show up when redirecting stderr.
I usually run a cargo check
or cargo build
before running tests, so if there are any errors outside the test code, I won't proceed to running cargo test 2>/dev/null
.
(If there are errors in the actual test code, then cargo test
prints the Build failed, waiting for other jobs to finish...
message even when stderr is redirected.)
cargo rustc -- -Awarnings
Fair enough.
Gotcha.