Skip to content

Commit 63cb62d

Browse files
committed
Deduplicate warnings about missing rustfmt
There's now exactly one warning per new crate instead of one per source file. Also warnings are being logged now, not printed to console.
1 parent f8edf75 commit 63cb62d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/cargo/ops/cargo_new.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,14 @@ 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+
681689
for i in &opts.source_files {
682690
let path_of_source_file = path.join(i.relative_path.clone());
683691

@@ -709,10 +717,9 @@ mod tests {
709717
{
710718
paths::write(&path_of_source_file, default_file_content)?;
711719

712-
// Format the newly created source file with rustfmt
713-
if let Err(e) = Command::new("rustfmt").arg(&path_of_source_file).output() {
714-
let msg = format!("failed to format {}: {}", path_of_source_file.display(), e);
715-
config.shell().warn(msg)?;
720+
// Format the newly created source file
721+
if rustfmt_exists {
722+
Command::new("rustfmt").arg(&path_of_source_file).output()?;
716723
}
717724
}
718725
}

0 commit comments

Comments
 (0)