Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ repository = "https://github.com/rust-lang/rustc-hash"
edition = "2021"
rust-version = "1.77"

[workspace.lints.clippy]
cast_lossless = "warn"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the number of other as casts here anyway, I don't see much value in this. The lint is pedantic for a reason; if you want to "fix" a pedantic lint I think you need better justification than what it says in the lint, since that wasn't enough to make it warn-by-default even in clippy.


[features]
default = ["std"]
std = []
Expand All @@ -18,3 +21,6 @@ rand = ["dep:rand", "std"]

[dependencies]
rand = { version = "0.9", optional = true }

[lints]
workspace = true
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ fn multiply_mix(x: u64, y: u64) -> u64 {
)) {
// We compute the full u64 x u64 -> u128 product, this is a single mul
// instruction on x86-64, one mul plus one mulhi on ARM64.
let full = (x as u128).wrapping_mul(y as u128);
let full = u128::from(x).wrapping_mul(u128::from(y));
let lo = full as u64;
let hi = (full >> 64) as u64;
Comment on lines -218 to 220

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to change something here, I think a much better change would to stop needing all the explicit widening and narrowing in the first place.

The fix for the ases here isn't from, IMHO, but something more like

let (lo, hi) = x.carrying_mul(y, 0);


Expand All @@ -239,8 +239,8 @@ fn multiply_mix(x: u64, y: u64) -> u64 {
let hy = (y >> 32) as u32;

// u32 x u32 -> u64 the low bits of one with the high bits of the other.
let afull = (lx as u64).wrapping_mul(hy as u64);
let bfull = (hx as u64).wrapping_mul(ly as u64);
let afull = u64::from(lx).wrapping_mul(u64::from(hy));
let bfull = u64::from(hx).wrapping_mul(u64::from(ly));

// Combine, swapping low/high of one of them so the upper bits of the
// product of one combine with the lower bits of the other.
Expand Down Expand Up @@ -271,14 +271,14 @@ fn hash_bytes(bytes: &[u8]) -> u64 {
s0 ^= u64::from_le_bytes(bytes[0..8].try_into().unwrap());
s1 ^= u64::from_le_bytes(bytes[len - 8..].try_into().unwrap());
} else if len >= 4 {
s0 ^= u32::from_le_bytes(bytes[0..4].try_into().unwrap()) as u64;
s1 ^= u32::from_le_bytes(bytes[len - 4..].try_into().unwrap()) as u64;
s0 ^= u64::from(u32::from_le_bytes(bytes[0..4].try_into().unwrap()));
s1 ^= u64::from(u32::from_le_bytes(bytes[len - 4..].try_into().unwrap()));
} else if len > 0 {
let lo = bytes[0];
let mid = bytes[len / 2];
let hi = bytes[len - 1];
s0 ^= lo as u64;
s1 ^= ((hi as u64) << 8) | mid as u64;
s0 ^= u64::from(lo);
s1 ^= (u64::from(hi) << 8) | u64::from(mid);
}
} else {
// Handle bulk (can partially overlap with suffix).
Expand Down
Loading