From c5f020a64014d461ce997ea6e2e801f17aa44b08 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Sat, 17 Mar 2018 10:40:49 +0100 Subject: [PATCH 1/2] Make the deprecated unstable SipHasher24 type private. It is still used by the deprecated *stable* `SipHasher` type. --- src/libcore/hash/mod.rs | 2 +- src/libcore/hash/sip.rs | 45 +++++------------------------------ src/libcore/tests/hash/sip.rs | 12 +++++----- 3 files changed, 13 insertions(+), 46 deletions(-) diff --git a/src/libcore/hash/mod.rs b/src/libcore/hash/mod.rs index 15545a04b64de..90d9ab3644a82 100644 --- a/src/libcore/hash/mod.rs +++ b/src/libcore/hash/mod.rs @@ -101,7 +101,7 @@ pub use self::sip::SipHasher; #[unstable(feature = "sip_hash_13", issue = "34767")] #[allow(deprecated)] -pub use self::sip::{SipHasher13, SipHasher24}; +pub use self::sip::SipHasher13; mod sip; diff --git a/src/libcore/hash/sip.rs b/src/libcore/hash/sip.rs index 4e4d9b3f1e2f0..7790118fbde1c 100644 --- a/src/libcore/hash/sip.rs +++ b/src/libcore/hash/sip.rs @@ -38,7 +38,7 @@ pub struct SipHasher13 { #[rustc_deprecated(since = "1.13.0", reason = "use `std::collections::hash_map::DefaultHasher` instead")] #[derive(Debug, Clone, Default)] -pub struct SipHasher24 { +struct SipHasher24 { hasher: Hasher, } @@ -156,7 +156,9 @@ impl SipHasher { #[rustc_deprecated(since = "1.13.0", reason = "use `std::collections::hash_map::DefaultHasher` instead")] pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher { - SipHasher(SipHasher24::new_with_keys(key0, key1)) + SipHasher(SipHasher24 { + hasher: Hasher::new_with_keys(key0, key1) + }) } } @@ -182,28 +184,6 @@ impl SipHasher13 { } } -impl SipHasher24 { - /// Creates a new `SipHasher24` with the two initial keys set to 0. - #[inline] - #[unstable(feature = "sip_hash_13", issue = "34767")] - #[rustc_deprecated(since = "1.13.0", - reason = "use `std::collections::hash_map::DefaultHasher` instead")] - pub fn new() -> SipHasher24 { - SipHasher24::new_with_keys(0, 0) - } - - /// Creates a `SipHasher24` that is keyed off the provided keys. - #[inline] - #[unstable(feature = "sip_hash_13", issue = "34767")] - #[rustc_deprecated(since = "1.13.0", - reason = "use `std::collections::hash_map::DefaultHasher` instead")] - pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher24 { - SipHasher24 { - hasher: Hasher::new_with_keys(key0, key1) - } - } -} - impl Hasher { #[inline] fn new_with_keys(key0: u64, key1: u64) -> Hasher { @@ -271,12 +251,12 @@ impl Hasher { impl super::Hasher for SipHasher { #[inline] fn write(&mut self, msg: &[u8]) { - self.0.write(msg) + self.0.hasher.write(msg) } #[inline] fn finish(&self) -> u64 { - self.0.finish() + self.0.hasher.finish() } } @@ -293,19 +273,6 @@ impl super::Hasher for SipHasher13 { } } -#[unstable(feature = "sip_hash_13", issue = "34767")] -impl super::Hasher for SipHasher24 { - #[inline] - fn write(&mut self, msg: &[u8]) { - self.hasher.write(msg) - } - - #[inline] - fn finish(&self) -> u64 { - self.hasher.finish() - } -} - impl super::Hasher for Hasher { // see short_write comment for explanation #[inline] diff --git a/src/libcore/tests/hash/sip.rs b/src/libcore/tests/hash/sip.rs index c6dd41798f2a7..bad858011e960 100644 --- a/src/libcore/tests/hash/sip.rs +++ b/src/libcore/tests/hash/sip.rs @@ -11,7 +11,7 @@ #![allow(deprecated)] use core::hash::{Hash, Hasher}; -use core::hash::{SipHasher, SipHasher13, SipHasher24}; +use core::hash::{SipHasher, SipHasher13}; use core::{slice, mem}; // Hash just the bytes of the slice, without length prefix @@ -224,14 +224,14 @@ fn test_siphash_2_4() { let k1 = 0x_0f_0e_0d_0c_0b_0a_09_08; let mut buf = Vec::new(); let mut t = 0; - let mut state_inc = SipHasher24::new_with_keys(k0, k1); + let mut state_inc = SipHasher::new_with_keys(k0, k1); while t < 64 { let vec = u8to64_le!(vecs[t], 0); - let out = hash_with(SipHasher24::new_with_keys(k0, k1), &Bytes(&buf)); + let out = hash_with(SipHasher::new_with_keys(k0, k1), &Bytes(&buf)); assert_eq!(vec, out); - let full = hash_with(SipHasher24::new_with_keys(k0, k1), &Bytes(&buf)); + let full = hash_with(SipHasher::new_with_keys(k0, k1), &Bytes(&buf)); let i = state_inc.finish(); assert_eq!(full, i); @@ -322,13 +322,13 @@ fn test_hash_no_concat_alias() { #[test] fn test_write_short_works() { let test_usize = 0xd0c0b0a0usize; - let mut h1 = SipHasher24::new(); + let mut h1 = SipHasher::new(); h1.write_usize(test_usize); h1.write(b"bytes"); h1.write(b"string"); h1.write_u8(0xFFu8); h1.write_u8(0x01u8); - let mut h2 = SipHasher24::new(); + let mut h2 = SipHasher::new(); h2.write(unsafe { slice::from_raw_parts(&test_usize as *const _ as *const u8, mem::size_of::()) From 89ecb0d5424f4eb72de70c0b7b0c3fb819273728 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Sat, 17 Mar 2018 11:07:50 +0100 Subject: [PATCH 2/2] Mark deprecated unstable SipHasher13 as a doc-hidden impl detail of HashMap. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It stays in libcore rather than being private in HashMap’s module because it shares code with the deprecated *stable* `SipHasher` type. --- src/libcore/hash/mod.rs | 3 ++- src/libcore/hash/sip.rs | 11 ++++++----- src/libcore/tests/lib.rs | 2 +- src/libstd/lib.rs | 3 +-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/libcore/hash/mod.rs b/src/libcore/hash/mod.rs index 90d9ab3644a82..ab714645675af 100644 --- a/src/libcore/hash/mod.rs +++ b/src/libcore/hash/mod.rs @@ -99,8 +99,9 @@ use mem; #[allow(deprecated)] pub use self::sip::SipHasher; -#[unstable(feature = "sip_hash_13", issue = "34767")] +#[unstable(feature = "hashmap_internals", issue = "0")] #[allow(deprecated)] +#[doc(hidden)] pub use self::sip::SipHasher13; mod sip; diff --git a/src/libcore/hash/sip.rs b/src/libcore/hash/sip.rs index 7790118fbde1c..e3bdecdc4b1fd 100644 --- a/src/libcore/hash/sip.rs +++ b/src/libcore/hash/sip.rs @@ -23,10 +23,11 @@ use mem; /// (eg. `collections::HashMap` uses it by default). /// /// See: -#[unstable(feature = "sip_hash_13", issue = "34767")] +#[unstable(feature = "hashmap_internals", issue = "0")] #[rustc_deprecated(since = "1.13.0", reason = "use `std::collections::hash_map::DefaultHasher` instead")] #[derive(Debug, Clone, Default)] +#[doc(hidden)] pub struct SipHasher13 { hasher: Hasher, } @@ -34,7 +35,7 @@ pub struct SipHasher13 { /// An implementation of SipHash 2-4. /// /// See: -#[unstable(feature = "sip_hash_13", issue = "34767")] +#[unstable(feature = "hashmap_internals", issue = "0")] #[rustc_deprecated(since = "1.13.0", reason = "use `std::collections::hash_map::DefaultHasher` instead")] #[derive(Debug, Clone, Default)] @@ -165,7 +166,7 @@ impl SipHasher { impl SipHasher13 { /// Creates a new `SipHasher13` with the two initial keys set to 0. #[inline] - #[unstable(feature = "sip_hash_13", issue = "34767")] + #[unstable(feature = "hashmap_internals", issue = "0")] #[rustc_deprecated(since = "1.13.0", reason = "use `std::collections::hash_map::DefaultHasher` instead")] pub fn new() -> SipHasher13 { @@ -174,7 +175,7 @@ impl SipHasher13 { /// Creates a `SipHasher13` that is keyed off the provided keys. #[inline] - #[unstable(feature = "sip_hash_13", issue = "34767")] + #[unstable(feature = "hashmap_internals", issue = "0")] #[rustc_deprecated(since = "1.13.0", reason = "use `std::collections::hash_map::DefaultHasher` instead")] pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher13 { @@ -260,7 +261,7 @@ impl super::Hasher for SipHasher { } } -#[unstable(feature = "sip_hash_13", issue = "34767")] +#[unstable(feature = "hashmap_internals", issue = "0")] impl super::Hasher for SipHasher13 { #[inline] fn write(&mut self, msg: &[u8]) { diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs index e53964b5769bd..1c876fa0bd7d0 100644 --- a/src/libcore/tests/lib.rs +++ b/src/libcore/tests/lib.rs @@ -21,6 +21,7 @@ #![feature(fixed_size_array)] #![feature(flt2dec)] #![feature(fmt_internals)] +#![feature(hashmap_internals)] #![feature(iterator_step_by)] #![feature(i128_type)] #![cfg_attr(stage0, feature(inclusive_range_syntax))] @@ -35,7 +36,6 @@ #![feature(range_is_empty)] #![feature(raw)] #![feature(refcell_replace_swap)] -#![feature(sip_hash_13)] #![feature(slice_patterns)] #![feature(sort_internals)] #![feature(specialization)] diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 70a1f82c9a159..62bef4bc49913 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -267,7 +267,7 @@ #![feature(fn_traits)] #![feature(fnbox)] #![feature(generic_param_attrs)] -#![feature(hashmap_hasher)] +#![feature(hashmap_internals)] #![feature(heap_api)] #![feature(i128)] #![feature(i128_type)] @@ -298,7 +298,6 @@ #![feature(raw)] #![feature(rustc_attrs)] #![feature(stdsimd)] -#![feature(sip_hash_13)] #![feature(slice_bytes)] #![feature(slice_concat_ext)] #![feature(slice_internals)]