Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format placeholder code when generating a crate #7827

7 changes: 7 additions & 0 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::fmt;
use std::fs;
use std::io::{BufRead, BufReader, ErrorKind};
use std::path::{Path, PathBuf};
use std::process::Command;
use std::str::FromStr;

use toml;
Expand Down Expand Up @@ -707,6 +708,12 @@ mod tests {
.unwrap_or(false)
{
paths::write(&path_of_source_file, default_file_content)?;

// Format the newly created source file with rustfmt
if let Err(e) = Command::new("rustfmt").arg(&path_of_source_file).output() {
let msg = format!("failed to format {}: {}", path_of_source_file.display(), e);
config.shell().warn(msg)?;
Kinrany marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

Expand Down