Skip to content

Commit

Permalink
fix: do not panic when failed to parse rustc commit-hash
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
weihanglo committed Nov 12, 2023
1 parent fa62a0e commit ba93b5c
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/cargo/util/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,19 @@ impl Rustc {
verbose_version
)
})?;
let commit_hash = extract("commit-hash: ").ok().map(|hash| {
debug_assert!(
hash.chars().all(|ch| ch.is_ascii_hexdigit()),
"commit hash must be a hex string, got: {hash:?}"
);
debug_assert!(
hash.len() == 40 || hash.len() == 64,
"hex string must be generated from sha1 or sha256 (i.e., it must be 40 or 64 characters long)\ngot: {hash:?}"
);
hash.to_string()
});
let commit_hash = extract("commit-hash: ").ok()
.filter(|hash| {
if !hash.chars().all(|ch| ch.is_ascii_hexdigit()) {
debug!("commit hash must be a hex string, got: {hash:?}");
return false;
}
if hash.len() != 40 && hash.len() != 64 {
debug!("hex string must be generated from sha1 or sha256 (i.e., it must be 40 or 64 characters long)\ngot: {hash:?}");
return false;
}
true
})
.map(|hash| hash.to_string());

Ok(Rustc {
path,
Expand Down

0 comments on commit ba93b5c

Please sign in to comment.