Skip to content
Merged
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
3 changes: 2 additions & 1 deletion library/core/src/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,8 @@ impl<H> Clone for BuildHasherDefault<H> {
}

#[stable(since = "1.7.0", feature = "build_hasher")]
impl<H> Default for BuildHasherDefault<H> {
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
impl<H> const Default for BuildHasherDefault<H> {
fn default() -> BuildHasherDefault<H> {
Self::new()
}
Expand Down
9 changes: 6 additions & 3 deletions library/core/src/hash/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,18 @@ impl SipHasher13 {
/// Creates a new `SipHasher13` with the two initial keys set to 0.
#[inline]
#[unstable(feature = "hashmap_internals", issue = "none")]
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
#[deprecated(since = "1.13.0", note = "use `std::hash::DefaultHasher` instead")]
pub fn new() -> SipHasher13 {
pub const fn new() -> SipHasher13 {
SipHasher13::new_with_keys(0, 0)
}

/// Creates a `SipHasher13` that is keyed off the provided keys.
#[inline]
#[unstable(feature = "hashmap_internals", issue = "none")]
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
#[deprecated(since = "1.13.0", note = "use `std::hash::DefaultHasher` instead")]
pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher13 {
pub const fn new_with_keys(key0: u64, key1: u64) -> SipHasher13 {
SipHasher13 { hasher: Hasher::new_with_keys(key0, key1) }
}
}
Expand Down Expand Up @@ -338,7 +340,8 @@ impl<S: Sip> Clone for Hasher<S> {
}
}

impl<S: Sip> Default for Hasher<S> {
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
impl<S: Sip> const Default for Hasher<S> {
/// Creates a `Hasher<S>` with the two initial keys set to 0.
#[inline]
fn default() -> Hasher<S> {
Expand Down
5 changes: 3 additions & 2 deletions library/std/src/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1444,9 +1444,10 @@ where
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<K, V, S> Default for HashMap<K, V, S>
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
impl<K, V, S> const Default for HashMap<K, V, S>
where
S: Default,
S: [const] Default,
{
/// Creates an empty `HashMap<K, V, S>`, with the `Default` value for the hasher.
#[inline]
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/collections/hash/map/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,4 +1053,7 @@ fn const_with_hasher() {
assert_eq!(y.len(), 0);
y.insert((), ());
assert_eq!(y.len(), 1);

const Z: HashMap<(), (), BuildHasherDefault<DefaultHasher>> = Default::default();
assert_eq!(X, Z);
}
7 changes: 4 additions & 3 deletions library/std/src/collections/hash/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,14 +1236,15 @@ where
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T, S> Default for HashSet<T, S>
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
impl<T, S> const Default for HashSet<T, S>
where
S: Default,
S: [const] Default,
{
/// Creates an empty `HashSet<T, S>` with the `Default` value for the hasher.
#[inline]
fn default() -> HashSet<T, S> {
HashSet { base: Default::default() }
HashSet { base: base::HashSet::with_hasher(Default::default()) }
}
}

Expand Down
2 changes: 2 additions & 0 deletions library/std/src/collections/hash/set/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,9 @@ fn from_array() {
#[test]
fn const_with_hasher() {
const X: HashSet<(), ()> = HashSet::with_hasher(());
const Y: HashSet<(), ()> = Default::default();
assert_eq!(X.len(), 0);
assert_eq!(Y.len(), 0);
}

#[test]
Expand Down
6 changes: 4 additions & 2 deletions library/std/src/hash/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,16 @@ impl DefaultHasher {
#[stable(feature = "hashmap_default_hasher", since = "1.13.0")]
#[inline]
#[allow(deprecated)]
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
#[must_use]
pub fn new() -> DefaultHasher {
pub const fn new() -> DefaultHasher {
DefaultHasher(SipHasher13::new_with_keys(0, 0))
}
}

#[stable(feature = "hashmap_default_hasher", since = "1.13.0")]
impl Default for DefaultHasher {
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
impl const Default for DefaultHasher {
/// Creates a new `DefaultHasher` using [`new`].
/// See its documentation for more.
///
Expand Down
Loading