Skip to content

Commit 5277a1f

Browse files
committed
Auto merge of #3614 - matthiaskrgr:rustc_tool_utils, r=phansch
rustc_tool_utils: fix failure to create proper non-repo version string when used in crates on crates.io, bump version
2 parents 84aa027 + 31d9630 commit 5277a1f

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

rustc_tools_util/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustc_tools_util"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["Matthias Krüger <[email protected]>"]
55
description = "small helper to generate version information for git packages"
66
repository = "https://github.com/rust-lang/rust-clippy"

rustc_tools_util/src/lib.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,17 @@ pub struct VersionInfo {
4646

4747
impl std::fmt::Display for VersionInfo {
4848
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49-
if self.commit_hash.is_some() {
49+
let hash = self.commit_hash.clone().unwrap_or_default();
50+
let hash_trimmed = hash.trim();
51+
52+
let date = self.commit_date.clone().unwrap_or_default();
53+
let date_trimmed = date.trim();
54+
55+
if (hash_trimmed.len() + date_trimmed.len()) > 0 {
5056
write!(
5157
f,
5258
"{} {}.{}.{} ({} {})",
53-
self.crate_name,
54-
self.major,
55-
self.minor,
56-
self.patch,
57-
self.commit_hash.clone().unwrap_or_default().trim(),
58-
self.commit_date.clone().unwrap_or_default().trim(),
59+
self.crate_name, self.major, self.minor, self.patch, hash_trimmed, date_trimmed,
5960
)?;
6061
} else {
6162
write!(f, "{} {}.{}.{}", self.crate_name, self.major, self.minor, self.patch)?;
@@ -121,7 +122,7 @@ mod test {
121122
let vi = get_version_info!();
122123
assert_eq!(vi.major, 0);
123124
assert_eq!(vi.minor, 1);
124-
assert_eq!(vi.patch, 0);
125+
assert_eq!(vi.patch, 1);
125126
assert_eq!(vi.crate_name, "rustc_tools_util");
126127
// hard to make positive tests for these since they will always change
127128
assert!(vi.commit_hash.is_none());
@@ -131,7 +132,7 @@ mod test {
131132
#[test]
132133
fn test_display_local() {
133134
let vi = get_version_info!();
134-
assert_eq!(vi.to_string(), "rustc_tools_util 0.1.0");
135+
assert_eq!(vi.to_string(), "rustc_tools_util 0.1.1");
135136
}
136137

137138
#[test]
@@ -140,7 +141,7 @@ mod test {
140141
let s = format!("{:?}", vi);
141142
assert_eq!(
142143
s,
143-
"VersionInfo { crate_name: \"rustc_tools_util\", major: 0, minor: 1, patch: 0 }"
144+
"VersionInfo { crate_name: \"rustc_tools_util\", major: 0, minor: 1, patch: 1 }"
144145
);
145146
}
146147

0 commit comments

Comments
 (0)