Skip to content

Commit ba93b5c

Browse files
committed
fix: do not panic when failed to parse rustc commit-hash
In some situation the commit-hash in `rustc -vV` output is "unknown". The debug assertion must not block any progress on others like miri, so removed and log instead.
1 parent fa62a0e commit ba93b5c

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/cargo/util/rustc.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,19 @@ impl Rustc {
8282
verbose_version
8383
)
8484
})?;
85-
let commit_hash = extract("commit-hash: ").ok().map(|hash| {
86-
debug_assert!(
87-
hash.chars().all(|ch| ch.is_ascii_hexdigit()),
88-
"commit hash must be a hex string, got: {hash:?}"
89-
);
90-
debug_assert!(
91-
hash.len() == 40 || hash.len() == 64,
92-
"hex string must be generated from sha1 or sha256 (i.e., it must be 40 or 64 characters long)\ngot: {hash:?}"
93-
);
94-
hash.to_string()
95-
});
85+
let commit_hash = extract("commit-hash: ").ok()
86+
.filter(|hash| {
87+
if !hash.chars().all(|ch| ch.is_ascii_hexdigit()) {
88+
debug!("commit hash must be a hex string, got: {hash:?}");
89+
return false;
90+
}
91+
if hash.len() != 40 && hash.len() != 64 {
92+
debug!("hex string must be generated from sha1 or sha256 (i.e., it must be 40 or 64 characters long)\ngot: {hash:?}");
93+
return false;
94+
}
95+
true
96+
})
97+
.map(|hash| hash.to_string());
9698

9799
Ok(Rustc {
98100
path,

0 commit comments

Comments
 (0)