From f82e935b96ee8f692e504237a66736e7bb29805b Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Wed, 21 Feb 2018 13:13:39 +0800 Subject: [PATCH] option_env and commit_info --- rustfmt-bin/build.rs | 4 ++-- rustfmt-bin/src/main.rs | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/rustfmt-bin/build.rs b/rustfmt-bin/build.rs index 7b7af66db07..c806b1f0408 100644 --- a/rustfmt-bin/build.rs +++ b/rustfmt-bin/build.rs @@ -26,8 +26,8 @@ fn main() { // Try to get hash and date of the last commit on a best effort basis. If anything goes wrong // (git not installed or if this is not a git repository) just return an empty string. fn commit_info() -> String { - match (commit_hash(), commit_date()) { - (Some(hash), Some(date)) => format!("{} ({} {})", channel(), hash.trim_right(), date), + match (channel(), commit_hash(), commit_date()) { + (channel, Some(hash), Some(date)) => format!("{} ({} {})", channel, hash.trim_right(), date), _ => String::new(), } } diff --git a/rustfmt-bin/src/main.rs b/rustfmt-bin/src/main.rs index abd5deea5be..a058887a696 100644 --- a/rustfmt-bin/src/main.rs +++ b/rustfmt-bin/src/main.rs @@ -386,14 +386,14 @@ fn print_usage_to_stdout(opts: &Options, reason: &str) { } fn print_version() { - println!( - "rustfmt {}", - concat!( - env!("CARGO_PKG_VERSION"), - "-", - include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt")) - ) + let version_info = format!( + "{}{}{}", + option_env!("CARGO_PKG_VERSION").unwrap_or("unknown"), + "-", + include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt")) ); + + println!("rustfmt {}", version_info); } fn determine_operation(matches: &Matches) -> FmtResult {