A common pattern today in Rust is to have two types of lint controls
- Project lints: defines the expected quality bar of the project
- Generally focused on
warn
to not get in the way of local development - Previously written via attributes or
.cargo/config.toml
but now supported in cargo via[lints]
- Generally focused on
- Lint enforcement: prevent project lints from being merged
- Currently handled via
RUSTFLAGS=-Dwarnings
though #8424 proposescargo check --warnings=deny
- Currently handled via
A gap that exists in this is lints you want reported to the user but you don't want to deny. You can handle this in CI by denying all warnings but allowing the individual lints (e.g. RUSTFLAGS=-D warnings --allow deprecated
)
Use cases
- Avoid deprecations from breaking CI. Having
Cargo.lock
checked in has helped with this but it can still be nice to decouple an upgrade from migrating APIs. I've gotten enough feedback on this in clap that I've put deprecations behind a feature flag. - Code-smell lints that you don't want enforced but are still good to know about
Problems
- Users can't tell what lints they are responsible for and which they aren't
- Cargo team is trying to find better ways of interacting with cargo/rust than rustflags particularly as this can help things like caching
- This is project-lint configuration stored away from the rest
Additional context: this doesn't just apply to rustc but clippy and rustdoc. In the future, this could also apply to cargo itself, cargo-semver-checks, cargo-audit, and whichever user-defined linting tool that makes it over the line. For example, cargo audit
s "unmaintained" warning falls into this category for me.
What if we added a new lint level notice
and had a dynamic lint group notices
(feel free to bikeshed names, remark
, consideration
). The difference from warn
/warnings
is
- Different, friendlier prefix/color
- Separate dynamic group so we can turn one to errors without affecting the other
I've not really seen this concept before in any ecosystem so I feel like there is a reason I'm missing for why not to do this. At least a quick search of internals only popped up Lint group for lints slightly below the warn-by-default bar - #2 by pitaj which is more about a static pedantic
group which has some superficial similarities but in the end is different.