Description
Summary
RFC: #3389
Implementation: #12148, #12168, #12174, #12174
Documentation: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#lints
Issues:
A-lints-table
This feature adds a [lints]
table to Cargo.toml
to configure reporting levels for rustc and other tool lints.
Testing instructions
Requires
- nightly: nightly-2023-05-25 or newer
betastable
Steps:
- Switch from attributes to
[lints]
table per the unstable reference
-Dwarnings
should likely still be passed in explicitly so local experimentation doesn't get blocked on perfection- CI jobs passing in
-Adeprecations
likely should still do so since users should see deprecation warnings locally to decide whether to address them
- Verify lints in CI with a supported compiler by adding the
-Zlints
flag
Debugging
- Build with
--verbose
to see what order[lints]
and otherRUSTFLAGS
are being passed to the underlying tool
Example: #12178
Updates Since RFC
cargo new
will automatically inherit the lints table (Automatically inherit workspace lints when running cargo new/init #12174)profile.rustflags
precedence with[lints]
was unspecified. We have put made it a higher precedence.- rustflags derived from
[lints]
table are not included inrustc -C metadata
hash. [lints]
should only apply to doctests as much as a diagnostic attributes (#[warn(...)]
) in an.rs
file applies to doctests- Per-target or per-target-kind (bin vs lib)
[lints]
tables is deferred (not in original RFC)- Workaround: using diagnostic attributes (e.g.
#[warn]
in the target) - This is helpful when production code (a subset of
[lib]
,[bin]
s in a workspace) want to be held to a higher standard than development code (especially tests)- e.g. clippy has an unwrap_used lint but people might want that in tests. clippy works around it today by having a
allow-unwrap-in-tests
setting
- e.g. clippy has an unwrap_used lint but people might want that in tests. clippy works around it today by having a
- Since workspaces can have non-production libs and bins, it almost seems like this is more of user-defined lint settings groups and inheriting specific groups. Or put another way, more design work is needed.
- Workaround: using diagnostic attributes (e.g.
- Workspace-wide lints are deferred until they are needed. See Tracking Issue for
[lints]
table RFC 3389 #12115 (comment) for ideas - We fingerprint all lints; we can optimize the fingerprinting later
Unresolved Issues
- Are we still comfortable with our schema choice? Add a
[lints]
table toCargo.toml
rfcs#3389 (comment) - Are we still comfortable with our precedence choice? Add a
[lints]
table toCargo.toml
rfcs#3389 (comment)
Feedback
Cases that don't work well:
- Some lints are crate specific, like only wanting
missing_docs
andmissing_debug_implementations
for[lib]
s (comment) - Some lints are package and maybe crate specific, like
disallowed_methods
in chore: dogfood Cargo-Zlints
table feature #12178 - Explicit inheritance doesn't work well when you want to catch lints for example packages but want the example package to standalone from the workspace (comment)
Future Extensions
No response
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done
Activity