Skip to content

User control over cargo warnings #12235

Closed

Description

@epage

Problem

Today, cargo maintainers are very cautious as to what warnings are created because they cannot be turned off by the user when they are intended. The problem is we've not had a mechanism to control it. With #12115, we'll now have a mechanism

Turning existing warnings into lints:

Porting clippy lints to cargo

Examples of new lints:

Proposed Solution

As package and workspace level lint control, turning existing warnings into diagnostics where possible

Tasks

Non-blocking

  • rustc-like diagnostics for parsing Cargo.lock
  • rustc-like diagnostics for parsing .cargo/config.toml
  • Deciding how to handle edition compatibility groups and groups in general (since refactor: Remove rust_2024_compatibility lint group #13740 skipped it for 2024)
    • Should we reuse rustc groups or not?
  • rustc-like diagnostics for processing Cargo.toml (ie port warnings off of shell.warn for consistency)
  • Diagnostic summary
  • Paths are not relative to the same root as rustc's

Rejected

  • _::warnings dynamic group (rust or cargo?): specialized warning for specific workflows that is being superseded by other mechanisms

Open questions

Notes

There will still be lints that are not related to the package but related to the user or / invocation. At a later stage, we can consider user-level lint levels.

Showing lint reason once per package:

  • When inherited, we could potentially show it once per workspace just like rustc would do for a crate level attribute
  • Starting with this now as an MVP, we can always re-evaluate later

Deferred reducing boilerplate

Deferred json messages

Deferred: whether to make lint docs more like clippy

Out of scope: CLI control. That would be evaluated for [lints] as a whole, potentially through config. Note that existing runtime lint control is not officially supported in Cargo but done through an escape hatch

Activity

  1. added
    A-diagnosticsArea: Error and warning messages generated by Cargo itself.
    C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
    S-triageStatus: This issue is waiting on initial triage.
    on Jun 6, 2023
  2. epage commented on Jun 6, 2023

    @epage
    ContributorAuthor

    From #10160 (comment)

    Just had a talk with @Muscraft. This is mostly my idea but it would be great if we have this kind of error overhaul. It will help things like JSON format message (#8283) or developing Cargo's own lint rules with -Zlints (#12115). It would also open a door to diagonostics translation (rust-lang/rust#100717). Probably the modularization of Cargo could benefit from it as well.

  3. epage commented on Jun 6, 2023

    @epage
    ContributorAuthor

    imo we need structured diagnostics which we pass to the diagnostic system which will then be turned into errors or something else

  4. epage commented on Jun 6, 2023

    @epage
    ContributorAuthor

    An obvious way to implement this is to shove the lint config in and our of Config as we enter and leave the relevant contexts. This is a bit more brittle and lowers our chances for doing some operations with threading as Config needs to be mutable everywhere

    One thought for how we could implement this

    • Rename Config to Context (we might want to do this anyways)
    • Refactor Context to allow decorating it (wrapping it)
    • Whenever we start down a workspace or package specific code path, we decorate the Context with that workspace or package's lint configuration
  5. added
    S-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
    E-hardExperience: Hard
    and removed
    S-triageStatus: This issue is waiting on initial triage.
    on Jun 11, 2023
  6. added a commit that references this issue on Jul 29, 2023
  7. added 2 commits that reference this issue on Jan 10, 2024
  8. added a commit that references this issue on Mar 4, 2024
  9. 21 remaining items

  10. added 13 commits that reference this issue on Aug 4, 2026
    5d91e48
    426df5f
    1ff9f29
    510d35d
    a06db8e
    d0b2a71
    642326a
    a491945
    cc4386a
    ea66401
    616a94d
    dd5ab8d
    d71a20d
  11. added a commit that references this issue on Aug 25, 2026
    94ba974
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-diagnosticsArea: Error and warning messages generated by Cargo itself.C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`E-hardExperience: HardS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions