rust-lang / rust-lang/rustfmt

`error_on_unformatted` doesn't actually make cargo fmt exit with non-zero

Open
#6,023 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-io C-bug only-with-option UO-error_on_unformatted
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

I tried this command in my repo.

$ cargo fmt --all -- --check --config unstable_features=true --config error_on_unformatted=true
error[internal]: not formatted because a comment would be lost
  --> /home/path/redacted/mod.rs:55
   |
92 |                 match rp.kind {
   |
   = note: set `error_on_unformatted = false` to suppress the warning against comments or string literals

warning: rustfmt has failed to format. See previous 1 errors.

I expected the command to exit with a non-zero status code to make sure it fails on CI, but it didn't. I suppose it's because the error[internal] is not actually an error, but a warning or smth like a non-failing error? I think this is a bug.

Versions

This behavior reproduces both on stable 1.74.0 and on nightly:

$cargo +nightly fmt --version
rustfmt 1.7.0-nightly (190f4c9 2024-01-09)
$ cargo +nightly --version    
cargo 1.77.0-nightly (2ce45605d 2024-01-04)
References

Tracking issue reference: https://github.com/rust-lang/rustfmt/issues/3392

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the exact cargo fmt --all -- --check --config unstable_features=true --config error_on_unformatted=true command using the reported stable or nightly versions. Trace how rustfmt reports the error_on_unformatted diagnostic and how cargo fmt determines its exit status. Done means the command exits non-zero for this condition, with regression coverage for the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.