rust-lang / rust-lang/rustfmt

--check does not exit with status code 1 when input file is stdin

Open
#5,376 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-config P-low
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

--check doe not exit with status code 1 if the input file is stdin, despite what --help says.

Honestly, this behavior is preferable for our usecase, as we can already tell if the input is formatted correctly by the presence of the output diff, and can use the status code for more fatal errors.

$ rustfmt --version
rustfmt 1.4.38-stable (fe5b13d 2022-05-18)
$ rustfmt --help
...
        --check         Run in 'check' mode. Exits with 0 if input is
                        formatted correctly. Exits with 1 and prints a diff if
                        formatting is required.
...
$ rustfmt --check < server.rs
Diff in <stdin> at line 12:
 impl Drop for Server {
     fn drop(&mut self) {
         if !thread::panicking() {
-                self.handle.take().unwrap().join().unwrap();
+            self.handle.take().unwrap().join().unwrap();
         }
     }
 }
$ echo $?
0
$ rustfmt --check server.rs
Diff in /ssd/aosp-master/external/rust/crates/openssl/openssl/src/ssl/test/server.rs at line 12:
 impl Drop for Server {
     fn drop(&mut self) {
         if !thread::panicking() {
-                self.handle.take().unwrap().join().unwrap();
+            self.handle.take().unwrap().join().unwrap();
         }
     }
 }
$ echo $?
1

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

Reproduce the reported commands with rustfmt --check < server.rs and rustfmt --check server.rs, then compare their output and exit codes with the --help description. Done should be defined by the intended stdin behavior and corresponding check-mode documentation or implementation.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.