@@ -7,6 +7,7 @@ use cargo_metadata;
7
7
use std:: cmp:: Ordering ;
8
8
use std:: collections:: { BTreeMap , BTreeSet } ;
9
9
use std:: env;
10
+ use std:: ffi:: OsStr ;
10
11
use std:: fs;
11
12
use std:: hash:: { Hash , Hasher } ;
12
13
use std:: io:: { self , Write } ;
@@ -129,6 +130,15 @@ fn execute() -> i32 {
129
130
}
130
131
}
131
132
133
+ fn rustfmt_command ( ) -> Command {
134
+ let rustfmt_var = env:: var_os ( "RUSTFMT" ) ;
135
+ let rustfmt = match & rustfmt_var {
136
+ Some ( rustfmt) => rustfmt,
137
+ None => OsStr :: new ( "rustfmt" ) ,
138
+ } ;
139
+ Command :: new ( rustfmt)
140
+ }
141
+
132
142
fn convert_message_format_to_rustfmt_args (
133
143
message_format : & str ,
134
144
rustfmt_args : & mut Vec < String > ,
@@ -205,7 +215,7 @@ fn handle_command_status(status: Result<i32, io::Error>) -> i32 {
205
215
}
206
216
207
217
fn get_rustfmt_info ( args : & [ String ] ) -> Result < i32 , io:: Error > {
208
- let mut command = Command :: new ( "rustfmt" )
218
+ let mut command = rustfmt_command ( )
209
219
. stdout ( std:: process:: Stdio :: inherit ( ) )
210
220
. args ( args)
211
221
. spawn ( )
@@ -484,7 +494,7 @@ fn run_rustfmt(
484
494
println ! ( ) ;
485
495
}
486
496
487
- let mut command = Command :: new ( "rustfmt" )
497
+ let mut command = rustfmt_command ( )
488
498
. stdout ( stdout)
489
499
. args ( files)
490
500
. args ( & [ "--edition" , edition] )
0 commit comments