From 768b60ab210d8caf3251097bc6a8b1f81d04aa95 Mon Sep 17 00:00:00 2001 From: Kinrany Date: Fri, 31 Jan 2020 01:36:30 +0300 Subject: [PATCH] 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. --- src/cargo/ops/cargo_new.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index 8d1dbb5e4..6bf57ce89 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -13,7 +13,7 @@ use std::fs; use std::io::{BufRead, BufReader, ErrorKind}; use std::path::{Path, PathBuf}; use std::process::Command; -use std::str::FromStr; +use std::str::{from_utf8, FromStr}; use toml; @@ -678,14 +678,6 @@ edition = {} // Create all specified source files (with respective parent directories) if they don't exist. - let rustfmt_exists = match Command::new("rustfmt").arg("-V").output() { - Ok(_) => true, - Err(e) => { - log::warn!("rustfmt not found: {}", e); - false - } - }; - for i in &opts.source_files { let path_of_source_file = path.join(i.relative_path.clone()); @@ -718,9 +710,14 @@ mod tests { paths::write(&path_of_source_file, default_file_content)?; // Format the newly created source file - if rustfmt_exists { - Command::new("rustfmt").arg(&path_of_source_file).output()?; - } + match Command::new("rustfmt").arg(&path_of_source_file).output() { + Err(e) => log::warn!("failed to call rustfmt: {}", e), + Ok(output) => { + if !output.status.success() { + log::warn!("rustfmt failed: {:?}", from_utf8(&output.stdout)); + } + } + }; } }