|
5 | 5 | use std::cmp::Ordering; |
6 | 6 | use std::collections::{BTreeMap, BTreeSet}; |
7 | 7 | use std::env; |
| 8 | +use std::ffi::OsStr; |
8 | 9 | use std::fs; |
9 | 10 | use std::hash::{Hash, Hasher}; |
10 | 11 | use std::io::{self, Write}; |
@@ -149,6 +150,15 @@ fn is_status_options(s: &str) -> bool { |
149 | 150 | || s.starts_with("--print-config=") |
150 | 151 | } |
151 | 152 |
|
| 153 | +fn rustfmt_command() -> Command { |
| 154 | + let rustfmt_var = env::var_os("RUSTFMT"); |
| 155 | + let rustfmt = match &rustfmt_var { |
| 156 | + Some(rustfmt) => rustfmt, |
| 157 | + None => OsStr::new("rustfmt"), |
| 158 | + }; |
| 159 | + Command::new(rustfmt) |
| 160 | +} |
| 161 | + |
152 | 162 | fn build_rustfmt_args(opts: &Opts, rustfmt_args: &mut Vec<String>) -> Result<(), String> { |
153 | 163 | let mut contains_check = false; |
154 | 164 | let mut contains_emit_mode = false; |
@@ -240,7 +250,7 @@ fn handle_command_status(status: Result<i32, io::Error>) -> i32 { |
240 | 250 | } |
241 | 251 |
|
242 | 252 | fn get_rustfmt_info(args: &[String]) -> Result<i32, io::Error> { |
243 | | - let mut command = Command::new("rustfmt") |
| 253 | + let mut command = rustfmt_command() |
244 | 254 | .stdout(std::process::Stdio::inherit()) |
245 | 255 | .args(args) |
246 | 256 | .spawn() |
@@ -625,7 +635,7 @@ fn run_rustfmt( |
625 | 635 | println!(); |
626 | 636 | } |
627 | 637 |
|
628 | | - let mut command = Command::new("rustfmt") |
| 638 | + let mut command = rustfmt_command() |
629 | 639 | .stdout(stdout) |
630 | 640 | .args(files) |
631 | 641 | .args(&["--edition", edition]) |
|
0 commit comments