Skip to content

Commit 768b60a

Browse files
committed
Log rustfmt output if it fails; also do not check that rustfmt exists
Worst case is that the logs will have multiple errors caused by missing rustfmt, so checking separately that rustfmt exists is unnecessary.
1 parent ea4f53c commit 768b60a

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/cargo/ops/cargo_new.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::fs;
1313
use std::io::{BufRead, BufReader, ErrorKind};
1414
use std::path::{Path, PathBuf};
1515
use std::process::Command;
16-
use std::str::FromStr;
16+
use std::str::{from_utf8, FromStr};
1717

1818
use toml;
1919

@@ -678,14 +678,6 @@ edition = {}
678678

679679
// Create all specified source files (with respective parent directories) if they don't exist.
680680

681-
let rustfmt_exists = match Command::new("rustfmt").arg("-V").output() {
682-
Ok(_) => true,
683-
Err(e) => {
684-
log::warn!("rustfmt not found: {}", e);
685-
false
686-
}
687-
};
688-
689681
for i in &opts.source_files {
690682
let path_of_source_file = path.join(i.relative_path.clone());
691683

@@ -718,9 +710,14 @@ mod tests {
718710
paths::write(&path_of_source_file, default_file_content)?;
719711

720712
// Format the newly created source file
721-
if rustfmt_exists {
722-
Command::new("rustfmt").arg(&path_of_source_file).output()?;
723-
}
713+
match Command::new("rustfmt").arg(&path_of_source_file).output() {
714+
Err(e) => log::warn!("failed to call rustfmt: {}", e),
715+
Ok(output) => {
716+
if !output.status.success() {
717+
log::warn!("rustfmt failed: {:?}", from_utf8(&output.stdout));
718+
}
719+
}
720+
};
724721
}
725722
}
726723

0 commit comments

Comments
 (0)