diff --git a/src/bin/main.rs b/src/bin/main.rs index 6959f56ccc7..1185454c8e7 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -450,13 +450,14 @@ are included as out of line modules from `src/lib.rs`." } fn print_version() { - let version_info = format!( - "{}-{}", - option_env!("CARGO_PKG_VERSION").unwrap_or("unknown"), - include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt")) - ); + let version_number = option_env!("CARGO_PKG_VERSION").unwrap_or("unknown"); + let commit_info = include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt")); - println!("rustfmt {version_info}"); + if commit_info.is_empty() { + println!("rustfmt {version_number}"); + } else { + println!("rustfmt {version_number}-{commit_info}"); + } } fn determine_operation(matches: &Matches) -> Result {