Skip to content

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

Open
@Colecf

Description

@Colecf

--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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions