Cargo rustc --benches -- -Awarnings

cargo rustc --benches -- -Awarnings fails (on both nightly and stable):

error: extra arguments to `rustc` can only be passed to one target, consider filtering
the package by passing, e.g., `--lib` or `--bin NAME` to specify a single target

Any tips, please?

The same error for cargo rustc --tests -- -Awarnings. If, hopefully with your help, I fix whatever mistake I'm doing, should applying it to tests work even if I also have benches/*? (Are benches and tests completely independent?) My benches are with Criterion, and with the following, if it matters:

[[bench]]
name = "with_criterion"
harness = false

What are you trying to achieve? cargo rustc allows to rustc with whatever parameters. If you want to check for warnings - there's cargo check or cargo bench...

I'd like to run cargo check --tests, or equivalent, but

  • suppressing any warnings, and showing errors only, and/but
  • not prefixed with RUSTFLAGS=-Awarnings, because that rebuilds it all (as per Suppress warnings from the cargo command? - #2 by cuviper), while
  • I'd like to switch between running cargo -check --tests with warnings and without warnings, without a full rebuild.

For now I resort to RUSTFLAGS=-Awarnings cargo check --tests, and once my code is stabilized, I'll check with warnings, too.

One thing that's new since that link is the lints section of the manifest, which applies to your own code and not your dependencies. So you could have a bit like this in Cargo.toml:

[lints.rust]
warnings = "allow"

... and tweak that as your development progresses.

1 Like

Thank you Josh @cuviper.

Also, adding #![allow(warnings, unused)] temporarily to my lib.rs and to the test involved works.

UPDATE: [lints.rust] can be better, since it applies to both lib.rs, benches/ (and probably to binary crates, too).

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.