Skip to content

Commit 1443bba

Browse files
authored
Fix path resolution of rustfmt in cargo-fmt (#6566)
Locate `rustfmt` in the same directory as `cargo-fmt` when the RUSTFMT env isn't set. Signed-off-by: onur-ozkan <[email protected]>
1 parent bf5f0ea commit 1443bba

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/cargo-fmt/main.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use std::cmp::Ordering;
77
use std::collections::{BTreeMap, BTreeSet};
88
use std::env;
9-
use std::ffi::OsStr;
109
use std::fs;
1110
use std::hash::{Hash, Hasher};
1211
use std::io::{self, Write};
@@ -151,11 +150,13 @@ fn execute() -> i32 {
151150
}
152151

153152
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"),
153+
let rustfmt = match env::var_os("RUSTFMT") {
154+
Some(rustfmt) => PathBuf::from(rustfmt),
155+
None => env::current_exe()
156+
.expect("current executable path invalid")
157+
.with_file_name("rustfmt"),
158158
};
159+
159160
Command::new(rustfmt)
160161
}
161162

0 commit comments

Comments
 (0)