Skip to content

Commit 04e29eb

Browse files
committed
Merge pull request #31392 from alexcrichton/beta-next
Merge in beta-accepted into beta
2 parents 2bd875d + 561e165 commit 04e29eb

File tree

14 files changed

+217
-142
lines changed

14 files changed

+217
-142
lines changed

src/libcore/hash/mod.rs

+72
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373

7474
use prelude::v1::*;
7575

76+
use marker;
7677
use mem;
7778

7879
#[stable(feature = "rust1", since = "1.0.0")]
@@ -190,6 +191,77 @@ pub trait Hasher {
190191
}
191192
}
192193

194+
/// A `BuildHasher` is typically used as a factory for instances of `Hasher`
195+
/// which a `HashMap` can then use to hash keys independently.
196+
///
197+
/// Note that for each instance of `BuildHasher` the create hashers should be
198+
/// identical. That is if the same stream of bytes is fed into each hasher the
199+
/// same output will also be generated.
200+
#[stable(since = "1.7.0", feature = "build_hasher")]
201+
pub trait BuildHasher {
202+
/// Type of the hasher that will be created.
203+
#[stable(since = "1.7.0", feature = "build_hasher")]
204+
type Hasher: Hasher;
205+
206+
/// Creates a new hasher.
207+
#[stable(since = "1.7.0", feature = "build_hasher")]
208+
fn build_hasher(&self) -> Self::Hasher;
209+
}
210+
211+
/// A structure which implements `BuildHasher` for all `Hasher` types which also
212+
/// implement `Default`.
213+
///
214+
/// This struct is 0-sized and does not need construction.
215+
#[stable(since = "1.7.0", feature = "build_hasher")]
216+
pub struct BuildHasherDefault<H>(marker::PhantomData<H>);
217+
218+
#[stable(since = "1.7.0", feature = "build_hasher")]
219+
impl<H: Default + Hasher> BuildHasher for BuildHasherDefault<H> {
220+
type Hasher = H;
221+
222+
fn build_hasher(&self) -> H {
223+
H::default()
224+
}
225+
}
226+
227+
#[stable(since = "1.7.0", feature = "build_hasher")]
228+
impl<H> Clone for BuildHasherDefault<H> {
229+
fn clone(&self) -> BuildHasherDefault<H> {
230+
BuildHasherDefault(marker::PhantomData)
231+
}
232+
}
233+
234+
#[stable(since = "1.7.0", feature = "build_hasher")]
235+
impl<H> Default for BuildHasherDefault<H> {
236+
fn default() -> BuildHasherDefault<H> {
237+
BuildHasherDefault(marker::PhantomData)
238+
}
239+
}
240+
241+
// The HashState trait is super deprecated, but it's here to have the blanket
242+
// impl that goes from HashState -> BuildHasher
243+
244+
/// Deprecated, renamed to `BuildHasher`
245+
#[unstable(feature = "hashmap_hasher", reason = "hasher stuff is unclear",
246+
issue = "27713")]
247+
#[rustc_deprecated(since = "1.7.0", reason = "support moved to std::hash and \
248+
renamed to BuildHasher")]
249+
pub trait HashState {
250+
/// Type of the hasher that will be created.
251+
type Hasher: Hasher;
252+
253+
/// Creates a new hasher based on the given state of this object.
254+
fn hasher(&self) -> Self::Hasher;
255+
}
256+
257+
#[unstable(feature = "hashmap_hasher", reason = "hasher stuff is unclear",
258+
issue = "27713")]
259+
#[allow(deprecated)]
260+
impl<T: HashState> BuildHasher for T {
261+
type Hasher = T::Hasher;
262+
fn build_hasher(&self) -> T::Hasher { self.hasher() }
263+
}
264+
193265
//////////////////////////////////////////////////////////////////////////////
194266

195267
mod impls {

src/librustc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#![feature(collections)]
3030
#![feature(const_fn)]
3131
#![feature(enumset)]
32-
#![feature(hashmap_hasher)]
3332
#![feature(iter_arith)]
3433
#![feature(libc)]
3534
#![feature(nonzero)]

src/librustc/util/common.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212

1313
use std::cell::{RefCell, Cell};
1414
use std::collections::HashMap;
15-
use std::collections::hash_state::HashState;
1615
use std::ffi::CString;
1716
use std::fmt::Debug;
18-
use std::hash::Hash;
17+
use std::hash::{Hash, BuildHasher};
1918
use std::iter::repeat;
2019
use std::path::Path;
2120
use std::time::Instant;
@@ -217,7 +216,7 @@ pub trait MemoizationMap {
217216
}
218217

219218
impl<K, V, S> MemoizationMap for RefCell<HashMap<K,V,S>>
220-
where K: Hash+Eq+Clone, V: Clone, S: HashState
219+
where K: Hash+Eq+Clone, V: Clone, S: BuildHasher
221220
{
222221
type Key = K;
223222
type Value = V;

src/librustc_data_structures/fnv.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@
99
// except according to those terms.
1010

1111
use std::collections::{HashMap, HashSet};
12-
use std::collections::hash_state::DefaultState;
1312
use std::default::Default;
14-
use std::hash::{Hasher, Hash};
13+
use std::hash::{Hasher, Hash, BuildHasherDefault};
1514

16-
pub type FnvHashMap<K, V> = HashMap<K, V, DefaultState<FnvHasher>>;
17-
pub type FnvHashSet<V> = HashSet<V, DefaultState<FnvHasher>>;
15+
pub type FnvHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FnvHasher>>;
16+
pub type FnvHashSet<V> = HashSet<V, BuildHasherDefault<FnvHasher>>;
1817

1918
#[allow(non_snake_case)]
2019
pub fn FnvHashMap<K: Hash + Eq, V>() -> FnvHashMap<K, V> {
21-
Default::default()
20+
HashMap::default()
2221
}
2322

2423
#[allow(non_snake_case)]
2524
pub fn FnvHashSet<V: Hash + Eq>() -> FnvHashSet<V> {
26-
Default::default()
25+
HashSet::default()
2726
}
2827

2928
/// A speedy hash algorithm for node ids and def ids. The hashmap in

src/librustc_data_structures/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
html_favicon_url = "https://www.rust-lang.org/favicon.ico",
2525
html_root_url = "https://doc.rust-lang.org/nightly/")]
2626

27-
#![feature(hashmap_hasher)]
2827
#![feature(nonzero)]
2928
#![feature(rustc_private)]
3029
#![feature(staged_api)]

src/librustc_mir/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
1717
#![crate_name = "rustc_mir"]
1818
#![crate_type = "rlib"]
1919
#![crate_type = "dylib"]
20+
#![unstable(feature = "rustc_private", issue = "27812")]
2021

2122
#![feature(rustc_private)]
23+
#![feature(staged_api)]
2224

2325
#[macro_use] extern crate log;
2426
extern crate graphviz as dot;

src/libserialize/collection_impls.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
//! Implementations of serialization for structures found in libcollections
1212
13-
use std::hash::Hash;
14-
use std::collections::hash_state::HashState;
13+
use std::hash::{Hash, BuildHasher};
1514
use std::mem;
1615

1716
use {Decodable, Encodable, Decoder, Encoder};
@@ -159,7 +158,7 @@ impl<
159158
impl<K, V, S> Encodable for HashMap<K, V, S>
160159
where K: Encodable + Hash + Eq,
161160
V: Encodable,
162-
S: HashState,
161+
S: BuildHasher,
163162
{
164163
fn encode<E: Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
165164
e.emit_map(self.len(), |e| {
@@ -177,12 +176,12 @@ impl<K, V, S> Encodable for HashMap<K, V, S>
177176
impl<K, V, S> Decodable for HashMap<K, V, S>
178177
where K: Decodable + Hash + Eq,
179178
V: Decodable,
180-
S: HashState + Default,
179+
S: BuildHasher + Default,
181180
{
182181
fn decode<D: Decoder>(d: &mut D) -> Result<HashMap<K, V, S>, D::Error> {
183182
d.read_map(|d, len| {
184183
let state = Default::default();
185-
let mut map = HashMap::with_capacity_and_hash_state(len, state);
184+
let mut map = HashMap::with_capacity_and_hasher(len, state);
186185
for i in 0..len {
187186
let key = try!(d.read_map_elt_key(i, |d| Decodable::decode(d)));
188187
let val = try!(d.read_map_elt_val(i, |d| Decodable::decode(d)));
@@ -195,7 +194,7 @@ impl<K, V, S> Decodable for HashMap<K, V, S>
195194

196195
impl<T, S> Encodable for HashSet<T, S>
197196
where T: Encodable + Hash + Eq,
198-
S: HashState,
197+
S: BuildHasher,
199198
{
200199
fn encode<E: Encoder>(&self, s: &mut E) -> Result<(), E::Error> {
201200
s.emit_seq(self.len(), |s| {
@@ -211,12 +210,12 @@ impl<T, S> Encodable for HashSet<T, S>
211210

212211
impl<T, S> Decodable for HashSet<T, S>
213212
where T: Decodable + Hash + Eq,
214-
S: HashState + Default,
213+
S: BuildHasher + Default,
215214
{
216215
fn decode<D: Decoder>(d: &mut D) -> Result<HashSet<T, S>, D::Error> {
217216
d.read_seq(|d, len| {
218217
let state = Default::default();
219-
let mut set = HashSet::with_capacity_and_hash_state(len, state);
218+
let mut set = HashSet::with_capacity_and_hasher(len, state);
220219
for i in 0..len {
221220
set.insert(try!(d.read_seq_elt(i, |d| Decodable::decode(d))));
222221
}

src/libserialize/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ Core encoding and decoding interfaces.
2929
#![feature(box_syntax)]
3030
#![feature(collections)]
3131
#![feature(enumset)]
32-
#![feature(hashmap_hasher)]
3332
#![feature(rustc_private)]
3433
#![feature(staged_api)]
3534
#![feature(str_char)]

0 commit comments

Comments
 (0)