From 0393e0c564daf3b3c05cb4412d042c7c17575743 Mon Sep 17 00:00:00 2001 From: Allan <6740989+allan2@users.noreply.github.com> Date: Tue, 10 Sep 2024 22:46:05 -0400 Subject: [PATCH 01/10] clippy use_self --- src/lib.rs | 10 +++++----- src/seeded_state.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1ca8f51..a4a5960 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,19 +76,19 @@ const K: usize = 0x93d765dd; impl FxHasher { /// Creates a `fx` hasher with a given seed. - pub const fn with_seed(seed: usize) -> FxHasher { - FxHasher { hash: seed } + pub const fn with_seed(seed: usize) -> Self { + Self { hash: seed } } /// Creates a default `fx` hasher. - pub const fn default() -> FxHasher { - FxHasher { hash: 0 } + pub const fn default() -> Self { + Self { hash: 0 } } } impl Default for FxHasher { #[inline] - fn default() -> FxHasher { + fn default() -> Self { Self::default() } } diff --git a/src/seeded_state.rs b/src/seeded_state.rs index 30efd27..9e6d940 100644 --- a/src/seeded_state.rs +++ b/src/seeded_state.rs @@ -24,7 +24,7 @@ pub struct FxSeededState { impl FxSeededState { /// Constructs a new `FxSeededState` that is initialized with a `seed`. - pub const fn with_seed(seed: usize) -> FxSeededState { + pub const fn with_seed(seed: usize) -> Self { Self { seed } } } From 638f04e5881cef2fe22781e9e84ead0c7b165b1f Mon Sep 17 00:00:00 2001 From: Allan <6740989+allan2@users.noreply.github.com> Date: Tue, 10 Sep 2024 22:49:37 -0400 Subject: [PATCH 02/10] clippy cast_lossless --- src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a4a5960..4f1bfde 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -201,7 +201,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) * (y as u128); + let full = u128::from(x) * u128::from(y); let lo = full as u64; let hi = (full >> 64) as u64; @@ -260,14 +260,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). From c0363f3fbfcbe48a78db1edf7a91d2c8aa2c86f2 Mon Sep 17 00:00:00 2001 From: Allan <6740989+allan2@users.noreply.github.com> Date: Tue, 10 Sep 2024 22:52:31 -0400 Subject: [PATCH 03/10] Partial clippy doc_markdown There were also warnings for math formulae and names like SipHash. No change at this time. --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 4f1bfde..8e3faf9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -243,7 +243,7 @@ fn multiply_mix(x: u64, y: u64) -> u64 { /// The 64-bit version of this hash passes the SMHasher3 test suite on the full /// 64-bit output, that is, f(hash_bytes(b) ^ f(seed)) for some good avalanching /// permutation f() passed all tests with zero failures. When using the 32-bit -/// version of multiply_mix this hash has a few non-catastrophic failures where +/// version of `multiply_mix` this hash has a few non-catastrophic failures where /// there are a handful more collisions than an optimal hash would give. /// /// We don't bother avalanching here as we'll feed this hash into a From 70ef92df83a95804c380b57f610c8371f39392c1 Mon Sep 17 00:00:00 2001 From: Allan <6740989+allan2@users.noreply.github.com> Date: Tue, 10 Sep 2024 23:01:26 -0400 Subject: [PATCH 04/10] clippy too_long_first_doc_paragraph --- src/lib.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8e3faf9..f3317bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,10 +48,9 @@ pub use seeded_state::FxSeededState; #[cfg(feature = "std")] pub use seeded_state::{FxHashMapSeed, FxHashSetSeed}; -/// A speedy hash algorithm for use within rustc. The hashmap in liballoc -/// by default uses SipHash which isn't quite as speedy as we want. In the -/// compiler we're not really worried about DOS attempts, so we use a fast -/// non-cryptographic hash. +/// A speedy hash algorithm for use within rustc. +/// +/// The hashmap in liballoc by default uses SipHash which isn't quite as speedy as we want. In the compiler we're not really worried about DOS attempts, so we use a fast non-cryptographic hash. /// /// The current implementation is a fast polynomial hash with a single /// bit rotation as a finishing step designed by Orson Peters. From b9c39736fc64e3310b69110dbc48f402513a1c3a Mon Sep 17 00:00:00 2001 From: Allan <6740989+allan2@users.noreply.github.com> Date: Tue, 10 Sep 2024 23:02:39 -0400 Subject: [PATCH 05/10] Add clippy exclusions --- src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index f3317bc..331bcc1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,11 @@ +#![allow( + clippy::unreadable_literal, + clippy::must_use_candidate, + clippy::module_name_repetitions, + clippy::doc_markdown, + clippy::cast_possible_truncation +)] + //! A speedy, non-cryptographic hashing algorithm used by `rustc`. //! //! # Example From 0d12f7d6589e49696c38ee14f527d705439c0a16 Mon Sep 17 00:00:00 2001 From: Allan <6740989+allan2@users.noreply.github.com> Date: Wed, 11 Sep 2024 07:02:47 -0400 Subject: [PATCH 06/10] clippy cargo_common_metadata --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 43e021c..7fe916f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ description = "A speedy, non-cryptographic hashing algorithm used by rustc" license = "Apache-2.0 OR MIT" readme = "README.md" keywords = ["hash", "hasher", "fxhash", "rustc"] +categories = ["algorithms"] repository = "https://github.com/rust-lang/rustc-hash" edition = "2021" From 82a98dd68037ad7ad7c3efd4d2536cc6bfff5af9 Mon Sep 17 00:00:00 2001 From: Allan <6740989+allan2@users.noreply.github.com> Date: Wed, 11 Sep 2024 07:02:56 -0400 Subject: [PATCH 07/10] Add clippy pedantic, nursery, cargo lint groups --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 331bcc1..a68905b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)] #![allow( clippy::unreadable_literal, clippy::must_use_candidate, From 2465b025fc276a7d3fc471e60429ba7157f8db70 Mon Sep 17 00:00:00 2001 From: Allan <6740989+allan2@users.noreply.github.com> Date: Thu, 12 Sep 2024 07:52:56 -0400 Subject: [PATCH 08/10] Shorten `FxHasher` doc comment Co-authored-by: Joe ST --- src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index a68905b..ef3a12a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -59,7 +59,8 @@ pub use seeded_state::{FxHashMapSeed, FxHashSetSeed}; /// A speedy hash algorithm for use within rustc. /// -/// The hashmap in liballoc by default uses SipHash which isn't quite as speedy as we want. In the compiler we're not really worried about DOS attempts, so we use a fast non-cryptographic hash. +/// The hashmap in liballoc by default uses SipHash which isn't quite as speedy as we want. +/// In the compiler we're not really worried about DOS attempts, so we use a fast non-cryptographic hash. /// /// The current implementation is a fast polynomial hash with a single /// bit rotation as a finishing step designed by Orson Peters. From cc979ed2bb65c75c7c656afda56c3fafcb39402d Mon Sep 17 00:00:00 2001 From: Allan <6740989+allan2@users.noreply.github.com> Date: Mon, 16 Sep 2024 22:47:36 -0400 Subject: [PATCH 09/10] Remove nursery lint group --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index ef3a12a..6e98bb2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)] +#![warn(clippy::all, clippy::pedantic, clippy::cargo)] #![allow( clippy::unreadable_literal, clippy::must_use_candidate, From 574930d1c0a142e00937e080ab823d4bcb212503 Mon Sep 17 00:00:00 2001 From: Allan <6740989+allan2@users.noreply.github.com> Date: Mon, 16 Sep 2024 22:48:58 -0400 Subject: [PATCH 10/10] Use `expect` lint check attribute --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 6e98bb2..fa2dee5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ #![warn(clippy::all, clippy::pedantic, clippy::cargo)] -#![allow( +#![expect( clippy::unreadable_literal, clippy::must_use_candidate, clippy::module_name_repetitions,