@@ -140,13 +140,13 @@ fn cargo_fmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
140140 args. push ( "--" ) ;
141141 args. push ( "--check" ) ;
142142 }
143- let success = exec ( context, "cargo" , path, & args) ?;
143+ let success = exec ( context, & bin_path ( "cargo" ) , path, & args) ?;
144144
145145 Ok ( success)
146146}
147147
148148fn rustfmt_test ( context : & FmtContext ) -> Result < ( ) , CliError > {
149- let program = "rustfmt" ;
149+ let program = bin_path ( "rustfmt" ) ;
150150 let dir = std:: env:: current_dir ( ) ?;
151151 let args = & [ "+nightly" , "--version" ] ;
152152
@@ -173,7 +173,7 @@ fn rustfmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
173173 if context. check {
174174 args. push ( "--check" . as_ref ( ) ) ;
175175 }
176- let success = exec ( context, "rustfmt" , std:: env:: current_dir ( ) ?, & args) ?;
176+ let success = exec ( context, & bin_path ( "rustfmt" ) , std:: env:: current_dir ( ) ?, & args) ?;
177177 if !success {
178178 eprintln ! ( "rustfmt failed on {}" , path. display( ) ) ;
179179 }
@@ -198,3 +198,12 @@ fn project_root() -> Result<PathBuf, CliError> {
198198
199199 Err ( CliError :: ProjectRootNotFound )
200200}
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 = PathBuf :: from ( std:: env:: var_os ( "CARGO_HOME" ) . unwrap ( ) ) ;
206+ p. push ( "bin" ) ;
207+ p. push ( bin) ;
208+ p. display ( ) . to_string ( )
209+ }
0 commit comments