Skip to content

Improve the rustc-side clippy development experience #76495

Description

@Aaron1011

When working on #75573, I ended up needing to modify Clippy (both a lint implementation and some UI tests). This process left a lot to be desired, and could be a significant roadblock to new contributors. I came up with some ideas for improving the process:

  • Run Clippy tests on the PR builder (if we have the CI budget). My PR was initially approved, then unapproved due to a (correct) suspicion that Clippy UI tests would be broken. However, this could easily be missed on other PRs, leading to wasted merge queue time and failed rollups. By running these tests on the PR builder, we could catch Clippy changes prior to PR approval.
  • Allow running Clippy tests in-tree from stage1. Currently, running ./x.py test src/tools/clippy requires a full compiler bootstrap (e.g. building a stage2 compiler). This takes a significant amount of time, and interacts badly with incremental compilation. For contributors with lower-end machines, this may make the contribution process incredibly frustrating. Attempting to build Clippy against a stage1 compiler (which requires running ./x.py test src/tools/clippy --stage 0 for some reason) works, but the tests fail with a confusing error about LLVM being missing.
  • Integrate Clippy UI tests with ./x.py test --bless. Currently, blessing Clippy UI tests requires manually running scripts from inside src/tools/clippy. It would be nice if ./x.py test --bless worked on all UI tests, allowing Clippy to be largely treated as 'just another directory'.
  • Document the interaction between -D warnings and Clippy lints. It seems as though denying a built-in lint with -D warnings prevents Clippy lints from being run. Since Clippy UI tests are run with -D warnings, adding a new builtin Rust lint can end up preventing Clippy UI tests from testing Clippy lints. Ideally, we would allow both sets of lints to run - if this is not possible, we should document the workaround (adding #![allow(problematic_rustc_lint)] to the affected Clippy UI tests).

Activity

  1. added
    T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Sep 8, 2020
  2. added
    T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
    T-infraRelevant to the infrastructure team, which will review and decide on the PR/issue.
    and removed
    T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.
    on Sep 8, 2020
  3. jyn514 commented on Jan 1, 2021

    @jyn514
    Member

    Note that at some point test --stage 0 src/tools/clippy broke: #78717

  4. RalfJung commented on Jun 2, 2021

    @RalfJung
    Member

    Last time I tried blessing clippy tests, that did not work, so I ended up manually adjusting stderr files. Maybe that's because I didn't try stage 2. Note that ./x.py test --bless (which is listed as 'working' in the list above) nowadays runs stage 1, so the OP text likely needs adjustments.

    @rust-lang/clippy this issue has remained open for more than half a year. The clippy-subtree-merger put the burden of keeping clippy working onto all rustc contributors, so having sub-par tooling like this is now a much bigger problem than it was back when only clippy devs had to use that tooling.

  5. jyn514 commented on Jun 2, 2021

    @jyn514
    Member

    Last time I tried blessing clippy tests, that did not work, so I ended up manually adjusting stderr files. Maybe that's because I didn't try stage 2.

    What was the error? That should work, if not it's a bug.

  6. flip1995 commented on Jun 2, 2021

    @flip1995
    Member

    ./x.py test --bless src/tools/clippy works. ./x.py test --bless does not run the Clippy tests, so it also doesn't update them.

  7. RalfJung commented on Jun 2, 2021

    @RalfJung
    Member

    I think ./x.py test --bless src/tools/clippy is what I tried and got tons of strange linking errors. I figured this was expected so I didn't report a bug, sorry.

  8. RalfJung commented on Jun 2, 2021

    @RalfJung
    Member

    Ah, turns out what I actually tried is ./x.py test src/tools/clippy --bless --stage 0, since I did not want to wait for two full rustc builds. (Stage 1 clippy uses the stage 1 rustc libs, so those have to be built first.)

  9. flip1995 commented on Jun 2, 2021

    @flip1995
    Member

    Run Clippy tests on the PR builder (if we have the CI budget)

    This is already done, if something in the src/tools/clippy is touched by the PR. IIRC the decision was made that running it on every PR is not necessary, since most PRs won't cause problems with it.

    Allow running Clippy tests in-tree from stage1

    That would be great. Unfortunately most Clippy folks don't really know how the bootstrapping works exactly and therefore fixing this would be really hard for us to do.

    Document the interaction between -D warnings and Clippy lints.

    Changes to rustc should not change Clippy tests, except for line number updates. The only exception I can think of is if a lint is being uplifted from Clippy to rustc. Fixing the issue where a new rust error/lint suppresses Clippy lints should be fixed by either adding #[allow(problematic_lint)] or by fixing the issue in the test, if it doesn't change the semantics of the test.

    Ah, turns out what I actually tried is ./x.py test src/tools/clippy --bless --stage 0

    Yes, Clippy on --stage 0 doesn't work (yet). I don't know how to fix that.

  10. jyn514 commented on Jun 2, 2021

    @jyn514
    Member

    That would be great. Unfortunately most Clippy folks don't really know how the bootstrapping works exactly and therefore fixing this would be really hard for us to do.

    The error that @RalfJung linked is not a bootstrapping issue. Clippy's fork of compile test needs to be fixed not to reuse the same target directory for tests as for building clippy itself.

  11. RalfJung commented on Jun 2, 2021

    @RalfJung
    Member

    Allow running Clippy tests in-tree from stage1

    That would be great. Unfortunately most Clippy folks don't really know how the bootstrapping works exactly and therefore fixing this would be really hard for us to do.

    Actually that works, since stage 1 is what x.py test uses by default -- right?
    Stage 0 doesn't work. That might be #78778, or it might be a separate problem.

  12. RalfJung commented on Jun 2, 2021

    @RalfJung
    Member

    Clippy's fork of compile test needs to be fixed not to reuse the same target directory for tests as for building clippy itself.

    Clippy uses the same fork that Miri uses, and Miri doesn't have this particular problem I think (at least, Miri worked on stage 0 before #78778 got introduced). However, it looks like clippy actually supports ui tests that depend on 3rd-party crates, so that logic might be wrong -- Miri doesn't have anything like this.

  13. flip1995 commented on Jun 2, 2021

    @flip1995
    Member

    Yes using external crates in compiletest causes some problems also in Clippy. So this is most likely the reason, why it also causes problems in the Rust repo.

  14. camsteffen commented on Jun 10, 2021

    @camsteffen
    Contributor

    I just opened rust-lang/rust-clippy#7343 to explain the problem from Clippy's side. I'd appreciate feedback from people with more rustc knowledge.

  15. added a commit that references this issue on May 7, 2022
  16. jyn514 commented on May 20, 2023

    @jyn514
    Member

    I have a prototype for running clippy tests without having to build rustc twice in #96798, which is currently blocked on changing the stage numbering for tools: https://rust-lang.zulipchat.com/#narrow/stream/326414-t-infra.2Fbootstrap/topic/Stage.20numbering.20for.20tools

    See #96798 (comment) for more details.

  17. added
    A-testsuiteArea: The testsuite used to check the correctness of rustc
    A-contributor-roadblockArea: Makes things more difficult for new or seasoned contributors to Rust
    and removed
    T-infraRelevant to the infrastructure team, which will review and decide on the PR/issue.
    on May 20, 2023
  18. jyn514 commented on Nov 16, 2023

    @jyn514
    Member
    • Document the interaction between -D warnings and Clippy lints. It seems as though denying a built-in lint with -D warnings prevents Clippy lints from being run. Since Clippy UI tests are run with -D warnings, adding a new builtin Rust lint can end up preventing Clippy UI tests from testing Clippy lints. Ideally, we would allow both sets of lints to run - if this is not possible, we should document the workaround (adding #![allow(problematic_rustc_lint)] to the affected Clippy UI tests).

    this is likely fixed since #87337, although i haven't tested

  19. added a commit that references this issue on Nov 16, 2023
  20. added a commit that references this issue on Dec 16, 2023
  21. added
    T-clippyRelevant to the Clippy team.
    and removed on Oct 8, 2025
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-contributor-roadblockArea: Makes things more difficult for new or seasoned contributors to RustA-testsuiteArea: The testsuite used to check the correctness of rustcC-bugCategory: This is a bug.T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)T-clippyRelevant to the Clippy team.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions