Skip to content

Commit 4e02f11

Browse files
committed
Auto merge of #12965 - weihanglo:hash, r=epage
fix: do not panic when failed to parse rustc commit-hash
2 parents 43abf90 + 7ca122c commit 4e02f11

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/cargo/util/rustc.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,20 @@ impl Rustc {
8383
)
8484
})?;
8585
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-
);
86+
// Possible commit-hash values from rustc are SHA hex string and "unknown". See:
87+
// * https://github.com/rust-lang/rust/blob/531cb83fc/src/bootstrap/src/utils/channel.rs#L73
88+
// * https://github.com/rust-lang/rust/blob/531cb83fc/compiler/rustc_driver_impl/src/lib.rs#L911-L913
89+
#[cfg(debug_assertions)]
90+
if hash != "unknown" {
91+
debug_assert!(
92+
hash.chars().all(|ch| ch.is_ascii_hexdigit()),
93+
"commit hash must be a hex string, got: {hash:?}"
94+
);
95+
debug_assert!(
96+
hash.len() == 40 || hash.len() == 64,
97+
"hex string must be generated from sha1 or sha256 (i.e., it must be 40 or 64 characters long)\ngot: {hash:?}"
98+
);
99+
}
94100
hash.to_string()
95101
});
96102

0 commit comments

Comments
 (0)