Skip to content

Pin Rust toolchain so pre-commit clippy matches CI #487

Closed

Description

@thiras

Problem

Pre-commit's cargo clippy hook can pass locally and then fail in CI when CI's stable toolchain is newer than the developer's local rustup install. PR #485 hit this — clippy 1.95 introduced clippy::duration_suboptimal_units, which fired on Duration::from_millis(1000) in the new test code. Locally I had rustc 1.93, so pre-commit was clean; CI runs dtolnay/rust-toolchain@stable which resolves to whatever stable is on the runner that day, found 1.95, and the lint failed.

Why pre-commit didn't catch it

  • rust-toolchain.toml says channel = "stable", but rustup only updates when the developer runs rustup update. There's no automatic pull on cargo invocations.
  • dtolnay/rust-toolchain@stable in CI grabs the latest stable on each run from the GitHub-hosted runner image (which itself updates regularly).
  • Result: a developer who rustup updated a few months ago gets a clippy that's missing every lint added since — including the one that fails their own PR.

Reproduction

$ rustc --version
rustc 1.93.0 (254b59607 2026-01-19)

$ cargo clippy --workspace --all-targets -- -D warnings
... clean ...

# Push, CI runs clippy 1.95 →
error: constructing a `Duration` using a smaller unit when a larger unit would be more readable
   --> crates/cli/src/commands/node_top.rs:776:13
    |
776 |             Duration::from_millis(1000),
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `-D clippy::duration-suboptimal-units` implied by `-D warnings`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#duration_suboptimal_units

Options

  1. Pin a specific stable in rust-toolchain.toml (e.g. channel = "1.95.0"). Reproducible, matches the workspace's MSRV-pinning ethos. Cost: someone has to bump it on a cadence, and a renovate/dependabot rule would help.
  2. Pin to a specific stable in the CI workflows too (replace dtolnay/rust-toolchain@stable with a specific version). Belt-and-suspenders with option 1.
  3. Add a pre-commit step that runs rustup update stable first. Always-fresh local toolchain. Cost: the first run after a stale period bumps the entire toolchain mid-commit.
  4. Document rustup update stable as a setup/onboarding step in CONTRIBUTING.md and rely on developers to refresh manually before pushing. Lighter-weight, partial coverage.
  5. Status quo — accept that pre-commit is best-effort and CI is authoritative. New-clippy-lint surprises are infrequent.

My preference is (1) + (2): pin the toolchain explicitly, and let renovate/dependabot bump it. This matches how the workspace already pins MSRV, and it makes the local-vs-CI equivalence reproducible. (4) is a worthwhile addition either way.

Why this matters now

Hit on PR #485 (feat: \decdn node top`); fixed in commit 61f4703 by replacing the four offending call sites with Duration::from_secs(1)`. The fix was 4-line mechanical, but I had to install rustc 1.95 locally to verify, push again, and wait for CI. That's the kind of round-trip pre-commit was supposed to prevent.

Out of scope

  • The pinning conversation should not change MSRV (rust-version.workspace = true → 1.85). MSRV is the lower bound we promise to compile on; stable is the upper bound we lint with. Distinct knobs.

Activity

  1. added
    kind:feature
    on May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:feature

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions