I would like to enforce some strict linting rules when compiling with the release profile and a bit laxer configuration when compiling with the dev or test profiles. For example, the dev profiles should allow unused imports, unused variables and dead code.
- All configurations enforce
deny(warnings)
. - My project is going to grow into a workspace with multiple library crates.
- All the crates within the workspace are going to share the linting configuration.
- In addition to rustc lints, I am using a lot of
deny
Clippy lints, some of which need to be allowed for the dev profiles.
It looks like the cleanest way to start is to define the base linting configuration within the [workspace.lints]
sections of my Cargo.toml.
What are my options to relax that base linting config for the dev and test profiles?
-
Can Cargo selectively apply some
[lints]
only when compiling with a specific profile? Can I manually pass lint options to rustc based on the profile? -
There is the unstable profile-rustflags Cargo feature. Currently, the downside is that this won’t work with the stable toolchain until the feature is stabilized. Also, I’m not sure if it is possible to configure Clippy lints this way.
-
Perhaps I could add something like
#![cfg_attr(debug_assertions, allow(dead_code, unreachable_code, unused_imports, unused_variables))]
to the root source file of each crate (all the main.rs and lib.rs files). Is there a simple way to avoid the code duplication and specify this allow list only once? -
Any other options?