@@ -140,13 +140,13 @@ fn cargo_fmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
140
140
args. push ( "--" ) ;
141
141
args. push ( "--check" ) ;
142
142
}
143
- let success = exec ( context, "cargo" , path, & args) ?;
143
+ let success = exec ( context, & bin_path ( "cargo" ) , path, & args) ?;
144
144
145
145
Ok ( success)
146
146
}
147
147
148
148
fn rustfmt_test ( context : & FmtContext ) -> Result < ( ) , CliError > {
149
- let program = "rustfmt" ;
149
+ let program = bin_path ( "rustfmt" ) ;
150
150
let dir = std:: env:: current_dir ( ) ?;
151
151
let args = & [ "+nightly" , "--version" ] ;
152
152
@@ -173,7 +173,7 @@ fn rustfmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
173
173
if context. check {
174
174
args. push ( "--check" . as_ref ( ) ) ;
175
175
}
176
- let success = exec ( context, "rustfmt" , std:: env:: current_dir ( ) ?, & args) ?;
176
+ let success = exec ( context, & bin_path ( "rustfmt" ) , std:: env:: current_dir ( ) ?, & args) ?;
177
177
if !success {
178
178
eprintln ! ( "rustfmt failed on {}" , path. display( ) ) ;
179
179
}
@@ -198,3 +198,12 @@ fn project_root() -> Result<PathBuf, CliError> {
198
198
199
199
Err ( CliError :: ProjectRootNotFound )
200
200
}
201
+
202
+ // Workaround for https://github.com/rust-lang/cargo/issues/7475.
203
+ // FIXME: replace `&bin_path("command")` with `"command"` once the issue is fixed
204
+ fn bin_path ( bin : & str ) -> String {
205
+ let mut p = home:: cargo_home ( ) . unwrap ( ) ;
206
+ p. push ( "bin" ) ;
207
+ p. push ( bin) ;
208
+ p. display ( ) . to_string ( )
209
+ }
0 commit comments