From cbf0baf6f900674cf88f266f96a4fa223895186b Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Mon, 29 Jun 2026 14:32:45 +0200 Subject: [PATCH] Use derive_const in nightly feature --- src/lib.rs | 30 ++---------------------------- src/random_state.rs | 2 +- 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b3270c3..5f151c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,6 +60,8 @@ pub use seeded_state::{FxHashMapSeed, FxHashSetSeed}; /// The current implementation is a fast polynomial hash with a single /// bit rotation as a finishing step designed by Orson Peters. #[derive(Clone)] +#[cfg_attr(not(feature = "nightly"), derive(Default))] +#[cfg_attr(feature = "nightly", derive_const(Default))] pub struct FxHasher { hash: usize, } @@ -90,34 +92,6 @@ impl FxHasher { } } -#[cfg(not(feature = "nightly"))] -macro_rules! default_impl { - () => { - impl Default for FxHasher { - #[inline] - fn default() -> FxHasher { - Self::default() - } - } - }; -} - -// In order to use the nightly-only `const` syntax, we gate the definition behind a macro so that -// parsing still succeeds on stable. -#[cfg(feature = "nightly")] -macro_rules! default_impl { - () => { - impl const Default for FxHasher { - #[inline] - fn default() -> FxHasher { - Self::default() - } - } - }; -} - -default_impl!(); - impl FxHasher { #[inline] fn add_to_hash(&mut self, i: usize) { diff --git a/src/random_state.rs b/src/random_state.rs index c8c35a0..3f4fe0a 100644 --- a/src/random_state.rs +++ b/src/random_state.rs @@ -92,7 +92,7 @@ mod tests { // `1 / 2.pow(bit_size_of::())`. Or 1/1.7e19 for 64 bit platforms or 1/4294967295 // for 32 bit platforms. I suppose this is acceptable. let a = FxHashMapRand::<&str, u32>::default(); - let b = thread::spawn(|| FxHashMapRand::<&str, u32>::default()) + let b = thread::spawn(FxHashMapRand::<&str, u32>::default) .join() .unwrap();