From eb06565fe3ee3c181939cc42075a8e199009e381 Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Thu, 20 Feb 2025 16:35:16 -0500 Subject: [PATCH] Account for Cargo's new hashing algorithm See: https://github.com/rust-lang/cargo/pull/14917 --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + dylint/Cargo.toml | 6 ++++-- dylint/src/library_packages/cargo_cli/util/hex.rs | 8 ++++---- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5aa5f9aa8..d8e68ed0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -942,6 +942,7 @@ dependencies = [ "log", "once_cell", "rewriter", + "rustc-stable-hash", "semver", "serde", "serde-untagged", @@ -3207,6 +3208,12 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustc-stable-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2febf9acc5ee5e99d1ad0afcdbccc02d87aa3f857a1f01f825b80eacf8edfcd1" + [[package]] name = "rustfix" version = "0.8.7" diff --git a/Cargo.toml b/Cargo.toml index c9371c536..6fa620636 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,6 +46,7 @@ predicates = "3.1" regex = "1.11" rewriter = "0.1" rust-embed = "8.5" +rustc-stable-hash = "0.1" rustversion = "1.0" semver = "1.0" serde = "1.0" diff --git a/dylint/Cargo.toml b/dylint/Cargo.toml index bb2ac31c6..934ec9f27 100644 --- a/dylint/Cargo.toml +++ b/dylint/Cargo.toml @@ -28,6 +28,7 @@ if_chain = { workspace = true, optional = true } log = { workspace = true } once_cell = { workspace = true } rewriter = { workspace = true, optional = true } +rustc-stable-hash = { workspace = true, optional = true } semver = { workspace = true } serde = { workspace = true } serde-untagged = { workspace = true, optional = true } @@ -84,6 +85,7 @@ __cargo_cli = [ "glob", "hex", "if_chain", + "rustc-stable-hash", "serde-untagged", "toml", "url", @@ -105,6 +107,6 @@ workspace = true # smoelius: When both `__cargo_cli` and `__cargo_lib` are enabled, we treat it as though # `--features=cargo-lib` was passed but the user forgot to pass `--no-default-features`. This -# approach causes `fs_extra` to look like an unused dependency. +# approach causes `fs_extra` and `rustc-stable-hash` to look like unused dependencies. [package.metadata.cargo-udeps.ignore] -normal = ["fs_extra"] +normal = ["fs_extra", "rustc-stable-hash"] diff --git a/dylint/src/library_packages/cargo_cli/util/hex.rs b/dylint/src/library_packages/cargo_cli/util/hex.rs index 2255cb752..9c7bded03 100644 --- a/dylint/src/library_packages/cargo_cli/util/hex.rs +++ b/dylint/src/library_packages/cargo_cli/util/hex.rs @@ -1,11 +1,11 @@ // smoelius: This file is a slight modification of: -// https://github.com/rust-lang/cargo/blob/aab416f6e68d555e8c9a0f02098a24946e0725fb/src/cargo/util/hex.rs +// https://github.com/rust-lang/cargo/blob/674e609a0ec2dc431575c48989a7bd1953ff2ab0/src/cargo/util/hex.rs #![allow(deprecated)] #![allow(clippy::module_name_repetitions)] #![cfg_attr(dylint_lib = "supplementary", allow(unnamed_constant))] -type StableHasher = std::hash::SipHasher; +type StableHasher = rustc_stable_hash::StableHasher; use std::fs::File; use std::hash::{Hash, Hasher}; @@ -18,7 +18,7 @@ pub fn to_hex(num: u64) -> String { pub fn hash_u64(hashable: H) -> u64 { let mut hasher = StableHasher::new(); hashable.hash(&mut hasher); - hasher.finish() + Hasher::finish(&hasher) } pub fn hash_u64_file(mut file: &File) -> std::io::Result { @@ -31,7 +31,7 @@ pub fn hash_u64_file(mut file: &File) -> std::io::Result { } hasher.write(&buf[..n]); } - Ok(hasher.finish()) + Ok(Hasher::finish(&hasher)) } pub fn short_hash(hashable: &H) -> String {