Skip to content
Merged
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
39 changes: 33 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
//! ```

#![no_std]
#![cfg_attr(feature = "nightly", feature(const_default))]
#![cfg_attr(feature = "nightly", feature(const_trait_impl))]
#![cfg_attr(feature = "nightly", feature(derive_const))]
#![cfg_attr(feature = "nightly", feature(hasher_prefixfree_extras))]
#![allow(rustc::default_hash_types)]

#[cfg(feature = "std")]
extern crate std;
Expand Down Expand Up @@ -86,13 +90,34 @@ impl FxHasher {
}
}

impl Default for FxHasher {
#[inline]
fn default() -> FxHasher {
Self::default()
}
#[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) {
Expand Down Expand Up @@ -315,7 +340,9 @@ fn hash_bytes(bytes: &[u8]) -> u64 {
/// use rustc_hash::FxBuildHasher;
/// assert_ne!(FxBuildHasher.hash_one(1), FxBuildHasher.hash_one(2));
/// ```
#[derive(Copy, Clone, Default)]
#[derive(Copy, Clone)]
#[cfg_attr(not(feature = "nightly"), derive(Default))]
#[cfg_attr(feature = "nightly", derive_const(Default))]
pub struct FxBuildHasher;

impl BuildHasher for FxBuildHasher {
Expand Down