Skip to content

Commit

Permalink
Account for Cargo's new hashing algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Feb 21, 2025
1 parent 0977ac5 commit eb06565
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions dylint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -84,6 +85,7 @@ __cargo_cli = [
"glob",
"hex",
"if_chain",
"rustc-stable-hash",
"serde-untagged",
"toml",
"url",
Expand All @@ -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"]
8 changes: 4 additions & 4 deletions dylint/src/library_packages/cargo_cli/util/hex.rs
Original file line number Diff line number Diff line change
@@ -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<rustc_stable_hash::hashers::SipHasher128>;

use std::fs::File;
use std::hash::{Hash, Hasher};
Expand All @@ -18,7 +18,7 @@ pub fn to_hex(num: u64) -> String {
pub fn hash_u64<H: Hash>(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<u64> {
Expand All @@ -31,7 +31,7 @@ pub fn hash_u64_file(mut file: &File) -> std::io::Result<u64> {
}
hasher.write(&buf[..n]);
}
Ok(hasher.finish())
Ok(Hasher::finish(&hasher))
}

pub fn short_hash<H: Hash>(hashable: &H) -> String {
Expand Down

0 comments on commit eb06565

Please sign in to comment.