Skip to content

Commit 67d0cac

Browse files
onur-ozkanytmimi
authored andcommitted
Fix path resolution of rustfmt in cargo-fmt
Instead of resolving `rustfmt` path from RUSTFMT or PATH envs, use the one located in the same directory as `cargo-fmt`. So that `cargo-fmt` uses the expected version of `rustfmt` to avoid accidental use of unrelated versions. Signed-off-by: onur-ozkan <[email protected]>
1 parent bf5f0ea commit 67d0cac

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/cargo-fmt/main.rs

Lines changed: 4 additions & 6 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,10 @@ 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"),
158-
};
153+
let rustfmt = env::current_exe()
154+
.expect("current executable path invalid")
155+
.with_file_name("rustfmt");
156+
159157
Command::new(rustfmt)
160158
}
161159

0 commit comments

Comments
 (0)