Skip to content

Commit 7da1989

Browse files
committed
denote which algorithms cargo supports
1 parent 683bda9 commit 7da1989

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2227,7 +2227,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
22272227
checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19"
22282228
dependencies = [
22292229
"cfg-if",
2230-
"windows-targets 0.48.5",
2230+
"windows-targets 0.52.5",
22312231
]
22322232

22332233
[[package]]

compiler/rustc_session/src/options.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ mod desc {
412412
pub const parse_merge_functions: &str = "one of: `disabled`, `trampolines`, or `aliases`";
413413
pub const parse_symbol_mangling_version: &str =
414414
"one of: `legacy`, `v0` (RFC 2603), or `hashed`";
415-
pub const parse_src_file_hash: &str = "either `md5`, `sha1`, or `sha256`";
415+
pub const parse_cargo_src_file_hash: &str = "one of `sha256`";
416+
pub const parse_src_file_hash: &str = "one of `md5`, `sha1`, or `sha256`";
416417
pub const parse_relocation_model: &str =
417418
"one of supported relocation models (`rustc --print relocation-models`)";
418419
pub const parse_code_model: &str = "one of supported code models (`rustc --print code-models`)";
@@ -1222,6 +1223,23 @@ mod parse {
12221223
true
12231224
}
12241225

1226+
pub(crate) fn parse_cargo_src_file_hash(
1227+
slot: &mut Option<SourceFileHashAlgorithm>,
1228+
v: Option<&str>,
1229+
) -> bool {
1230+
match v.and_then(|s| SourceFileHashAlgorithm::from_str(s).ok()) {
1231+
Some(hash_kind) => {
1232+
if hash_kind.supported_in_cargo() {
1233+
*slot = Some(hash_kind);
1234+
} else {
1235+
return false;
1236+
}
1237+
}
1238+
_ => return false,
1239+
}
1240+
true
1241+
}
1242+
12251243
pub(crate) fn parse_target_feature(slot: &mut String, v: Option<&str>) -> bool {
12261244
match v {
12271245
Some(s) => {
@@ -1609,8 +1627,8 @@ options! {
16091627
"instrument control-flow architecture protection"),
16101628
check_cfg_all_expected: bool = (false, parse_bool, [UNTRACKED],
16111629
"show all expected values in check-cfg diagnostics (default: no)"),
1612-
checksum_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_src_file_hash, [TRACKED],
1613-
"hash algorithm of source files used to check freshness in cargo (`md5`, `sha1`, or `sha256`)"),
1630+
checksum_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_cargo_src_file_hash, [TRACKED],
1631+
"hash algorithm of source files used to check freshness in cargo (`sha256`)"),
16141632
codegen_backend: Option<String> = (None, parse_opt_string, [TRACKED],
16151633
"the backend to use"),
16161634
combine_cgu: bool = (false, parse_bool, [TRACKED],

compiler/rustc_span/src/lib.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,12 +1460,21 @@ pub enum SourceFileHashAlgorithm {
14601460
Sha256,
14611461
}
14621462

1463+
impl SourceFileHashAlgorithm {
1464+
pub fn supported_in_cargo(&self) -> bool {
1465+
match self {
1466+
Self::Md5 | Self::Sha1 => false,
1467+
Self::Sha256 => true,
1468+
}
1469+
}
1470+
}
1471+
14631472
impl Display for SourceFileHashAlgorithm {
14641473
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14651474
f.write_str(match self {
1466-
SourceFileHashAlgorithm::Md5 => "md5",
1467-
SourceFileHashAlgorithm::Sha1 => "sha1",
1468-
SourceFileHashAlgorithm::Sha256 => "sha256",
1475+
Self::Md5 => "md5",
1476+
Self::Sha1 => "sha1",
1477+
Self::Sha256 => "sha256",
14691478
})
14701479
}
14711480
}

0 commit comments

Comments
 (0)