Skip to content

fix(cargo-anvil): make anvil-fmt actually run the pinned nightly rustfmt - #159

Open
Evgenii (Vaiz) wants to merge 3 commits into
mainfrom
u/vaiz/2026/09/04/anvil-fmt-nightly
Open

fix(cargo-anvil): make anvil-fmt actually run the pinned nightly rustfmt#159
Evgenii (Vaiz) wants to merge 3 commits into
mainfrom
u/vaiz/2026/09/04/anvil-fmt-nightly

Conversation

@Vaiz

@Vaiz Evgenii (Vaiz) commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🤖 Clawpilot here! Posted automatically by Clawpilot (an AI agent), not by a human. Please verify before acting.

What this changes

anvil-fmt pins both cargo each and its inner cargo fmt to rust_nightly. The outer invocation no longer selects the stable toolchain.

Effects

  • Check mode and --fix keep their existing behavior.
  • Workspace iteration keeps --keep-going and per-member manifest paths.
  • The recipe uses explicit +toolchain arguments, not a RUSTUP_TOOLCHAIN assignment.
  • Generated recipes, snapshots, and .anvil.lock match the template.

Reproduction limits

Current local probes select nightly rustfmt with both the proposed command and the original command. The earlier failure is not reproduced in this environment; its cause remains unresolved.

@codecov-commenter

Codecov Comments Bot (codecov-commenter) commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.5%. Comparing base (7a5daf3) to head (cd240b8).
⚠️ Report is 2 commits behind head on main.

❌ Your project status has failed because the head coverage (97.5%) is below the target coverage (100.0%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@           Coverage Diff           @@
##            main    #159     +/-   ##
=======================================
- Coverage   97.5%   97.5%   -0.1%     
=======================================
  Files        300     300             
  Lines      67799   67799             
=======================================
- Hits       66160   66154      -6     
- Misses      1639    1645      +6     
Flag Coverage Δ
linux 97.5% <ø> (-0.1%) ⬇️
linux-arm 97.5% <ø> (-0.1%) ⬇️
scheduled ?
windows 97.7% <ø> (-0.1%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change corrects toolchain selection for cargo fmt with a targeted regression test and consistent regenerated artifacts, with no remaining issues found in the reviewed diffs.

Pull request overview

This PR fixes anvil-fmt so it consistently runs the pinned nightly rustfmt by selecting the nightly toolchain via RUSTUP_TOOLCHAIN, ensuring unstable rustfmt.toml options are actually enforced even when an ambient/stable toolchain selection would otherwise leak into cargo fmt.

Changes:

  • Update the anvil-fmt check to set $env:RUSTUP_TOOLCHAIN to the pinned nightly and run cargo fmt without relying on nested +toolchain.
  • Add a regression test that simulates a hostile inherited RUSTUP_TOOLCHAIN and asserts the pinned nightly selection is still used for formatting-related cargo invocations.
  • Extend the “no implicit default cargo” invariant to treat a per-recipe RUSTUP_TOOLCHAIN pin as an explicit toolchain selection.
File summaries
File Description
justfiles/anvil/checks/fmt.just Pins nightly via RUSTUP_TOOLCHAIN and runs cargo each … cargo fmt … so rustfmt resolves under the intended toolchain.
crates/cargo-anvil/templates/justfiles/anvil/checks/fmt.just Template source updated to generate the fixed anvil-fmt recipe.
crates/cargo-anvil/tests/recipe_contracts.rs Adds/updates tests asserting correct cargo fmt invocation and toolchain pinning behavior under inherited toolchain env.
crates/cargo-anvil/src/anvil/artifacts/justfile.rs Updates invariant checking to allow explicit toolchain selection via per-recipe $env:RUSTUP_TOOLCHAIN pinning.
crates/cargo-anvil/tests/snapshots/snapshots__local_only.snap Snapshot update reflecting the generated fmt.just changes.
crates/cargo-anvil/tests/snapshots/snapshots__github_backend.snap Snapshot update reflecting the generated fmt.just changes.
crates/cargo-anvil/tests/snapshots/snapshots__ado_backend.snap Snapshot update reflecting the generated fmt.just changes.
.anvil.lock Updates checksums to match the regenerated artifacts/templates.
Review details
  • Files reviewed: 7/8 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Vaiz
Evgenii (Vaiz) force-pushed the u/vaiz/2026/09/04/anvil-fmt-nightly branch from 25ce18f to 966f52c Compare September 4, 2026 11:06
@Vaiz
Evgenii (Vaiz) marked this pull request as ready for review September 4, 2026 11:33
Copilot AI review requested due to automatic review settings September 4, 2026 11:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change directly addresses the described toolchain-leak failure mode and adds targeted contract coverage to prevent regressions under hostile ambient RUSTUP_TOOLCHAIN.

Review details
  • Files reviewed: 7/8 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 4, 2026 14:17
@Vaiz
Evgenii (Vaiz) force-pushed the u/vaiz/2026/09/04/anvil-fmt-nightly branch from 966f52c to 4ca357a Compare September 4, 2026 14:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is narrowly scoped, matches the stated failure mode, and includes targeted tests to prevent regressions under hostile RUSTUP_TOOLCHAIN environments.

Review details
  • Files reviewed: 7/8 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Comment thread justfiles/anvil/checks/fmt.just Outdated
Copilot AI review requested due to automatic review settings September 7, 2026 10:52
@Vaiz
Evgenii (Vaiz) force-pushed the u/vaiz/2026/09/04/anvil-fmt-nightly branch from 4ca357a to 01bf4f5 Compare September 7, 2026 10:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change directly addresses the described toolchain-leak failure mode and is backed by updated contract tests and regenerated snapshots without introducing new risk hotspots.

Review details
  • Files reviewed: 7/8 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Comment thread crates/cargo-anvil/templates/justfiles/anvil/checks/fmt.just
Copilot AI review requested due to automatic review settings September 7, 2026 12:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The implemented recipe/test changes don’t currently validate (and may not implement) the PR-described fix for hostile/ambient RUSTUP_TOOLCHAIN, so the original enforcement gap may remain.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 6/7 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread crates/cargo-anvil/templates/justfiles/anvil/checks/fmt.just
Comment thread crates/cargo-anvil/tests/recipe_contracts.rs
Evgenii (Vaiz) and others added 3 commits September 7, 2026 14:02
`cargo fmt` only dispatches: cargo-fmt runs `rustfmt` as a child process
through the rustup shim, and that shim reads `RUSTUP_TOOLCHAIN`, which
rustup exports into every child of a `+`-selected cargo and does not
rewrite when a nested cargo carries its own `+`. So the inner
`+{{ rust_nightly }}` selected a nightly cargo, but the `rustfmt`
underneath it still resolved through the outer stable selection. Stable
rustfmt does not fail on unstable options -- it downgrades each to a
warning and exits 0, so every unstable `rustfmt.toml` rule silently
stopped being enforced while the check kept passing.

Set `RUSTUP_TOOLCHAIN` for the recipe instead, which covers every
descendant. The wrapper loses its stable pin deliberately: that pin is
the thing that leaks, and `cargo each` only enumerates members, it
compiles nothing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Apply Martin's proposal instead of assigning RUSTUP_TOOLCHAIN in the
recipe. Preserve --fix, assert both explicit pins in the recipe
contracts, remove the now-unused environment-pin exception, and
regenerate the checked-in artifacts and snapshots.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Rebasing onto main picked up template changes (msrv-test.just, tools.just and the
GitHub workflow templates), so the catalog checksum recorded in .anvil.lock no
longer matched either side of the merge. Regenerated with
`cargo run -p cargo-anvil -- anvil`; `--dry-run` is now clean and no generated
artifact changed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Vaiz
Evgenii (Vaiz) force-pushed the u/vaiz/2026/09/04/anvil-fmt-nightly branch from 9d6bc65 to cd240b8 Compare September 7, 2026 14:05
Copilot AI review requested due to automatic review settings September 7, 2026 14:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is small, consistent across template/generated outputs, and the test/snapshot updates align with the new contract.

Review details
  • Files reviewed: 6/7 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants