File tree 1 file changed +8
-3
lines changed
1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -101,7 +101,7 @@ fn main() {
101
101
mut formatted,
102
102
} ) => {
103
103
if args. rustfmt {
104
- formatted = run_rustfmt ( & formatted) ;
104
+ formatted = run_rustfmt ( & formatted) . unwrap_or ( formatted ) ;
105
105
}
106
106
107
107
if args. check && check_if_diff ( None , & original, & formatted, true ) {
@@ -265,7 +265,7 @@ fn load_config(path: &PathBuf) -> anyhow::Result<FormatterSettings> {
265
265
Ok ( settings)
266
266
}
267
267
268
- fn run_rustfmt ( source : & str ) -> String {
268
+ fn run_rustfmt ( source : & str ) -> Option < String > {
269
269
let mut child = process:: Command :: new ( "rustfmt" )
270
270
. stdin ( Stdio :: piped ( ) )
271
271
. stdout ( Stdio :: piped ( ) )
@@ -280,5 +280,10 @@ fn run_rustfmt(source: &str) -> String {
280
280
. expect ( "failed to write to stdin" ) ;
281
281
282
282
let output = child. wait_with_output ( ) . expect ( "failed to read stdout" ) ;
283
- String :: from_utf8 ( output. stdout ) . expect ( "stdout is not valid utf8" )
283
+
284
+ if output. status . success ( ) {
285
+ Some ( String :: from_utf8 ( output. stdout ) . expect ( "stdout is not valid utf8" ) )
286
+ } else {
287
+ None
288
+ }
284
289
}
You can’t perform that action at this time.
0 commit comments