Skip to content

Tracking Issue for [lints] table RFC 3389 #12115

Closed
@ehuss

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 Area: [lints] table

This feature adds a [lints] table to Cargo.toml to configure reporting levels for rustc and other tool lints.

See also #3591, #5034

Testing instructions

Requires

  • nightly: nightly-2023-05-25 or newer
  • beta
  • stable

Steps:

  1. 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
  1. Verify lints in CI with a supported compiler by adding the -Zlints flag

Debugging

  • Build with --verbose to see what order [lints] and other RUSTFLAGS 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 in rustc -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
    • 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.
  • 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

Feedback

Cases that don't work well:

  • Some lints are crate specific, like only wanting missing_docs and missing_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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lints-tableArea: [lints] tableC-tracking-issueCategory: A tracking issue for something unstable.S-waiting-on-feedbackStatus: An implemented feature is waiting on community feedback for bugs or design concerns.T-cargoTeam: Cargodisposition-mergeFCP with intent to mergefinished-final-comment-periodFCP complete

    Type

    No type

    Projects

    • Status

      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions