Add insta-stable std:#️⃣:{DefaultHasher, RandomState} exports

This commit is contained in:
ltdk 2023-10-13 02:44:19 -04:00
parent 075409ddd9
commit 8337e86b28
19 changed files with 40 additions and 68 deletions

View File

@ -7,8 +7,7 @@ use rustc_hir::def_id::DefId;
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
use rustc_target::spec::abi; use rustc_target::spec::abi;
use std::borrow::Cow; use std::borrow::Cow;
use std::collections::hash_map::DefaultHasher; use std::hash::{DefaultHasher, Hash, Hasher};
use std::hash::{Hash, Hasher};
use std::path::PathBuf; use std::path::PathBuf;
#[derive(Clone, Copy, Debug, PartialEq, Eq, TypeFoldable, TypeVisitable)] #[derive(Clone, Copy, Debug, PartialEq, Eq, TypeFoldable, TypeVisitable)]

View File

@ -3179,9 +3179,8 @@ pub(crate) mod dep_tracking {
use rustc_target::spec::{ use rustc_target::spec::{
RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TargetTriple, TlsModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TargetTriple, TlsModel,
}; };
use std::collections::hash_map::DefaultHasher;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::hash::Hash; use std::hash::{DefaultHasher, Hash};
use std::num::NonZeroUsize; use std::num::NonZeroUsize;
use std::path::PathBuf; use std::path::PathBuf;

View File

@ -19,8 +19,7 @@ use rustc_span::SourceFileHashAlgorithm;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::collections::hash_map::DefaultHasher; use std::hash::{DefaultHasher, Hasher};
use std::hash::Hasher;
use std::num::{IntErrorKind, NonZeroUsize}; use std::num::{IntErrorKind, NonZeroUsize};
use std::path::PathBuf; use std::path::PathBuf;
use std::str; use std::str;

View File

@ -3537,7 +3537,7 @@ impl TargetTriple {
/// If this target is a path, a hash of the path is appended to the triple returned /// If this target is a path, a hash of the path is appended to the triple returned
/// by `triple()`. /// by `triple()`.
pub fn debug_triple(&self) -> String { pub fn debug_triple(&self) -> String {
use std::collections::hash_map::DefaultHasher; use std::hash::DefaultHasher;
match self { match self {
TargetTriple::TargetTriple(triple) => triple.to_owned(), TargetTriple::TargetTriple(triple) => triple.to_owned(),

View File

@ -271,7 +271,7 @@ pub(crate) mod test_helpers {
/// seed not being the same for every RNG invocation too. /// seed not being the same for every RNG invocation too.
pub(crate) fn test_rng() -> rand_xorshift::XorShiftRng { pub(crate) fn test_rng() -> rand_xorshift::XorShiftRng {
use std::hash::{BuildHasher, Hash, Hasher}; use std::hash::{BuildHasher, Hash, Hasher};
let mut hasher = std::collections::hash_map::RandomState::new().build_hasher(); let mut hasher = std::hash::RandomState::new().build_hasher();
std::panic::Location::caller().hash(&mut hasher); std::panic::Location::caller().hash(&mut hasher);
let hc64 = hasher.finish(); let hc64 = hasher.finish();
let seed_vec = let seed_vec =

View File

@ -2706,7 +2706,7 @@ impl<T: Clone, A: Allocator + Clone> Clone for Vec<T, A> {
/// ``` /// ```
/// use std::hash::BuildHasher; /// use std::hash::BuildHasher;
/// ///
/// let b = std::collections::hash_map::RandomState::new(); /// let b = std::hash::RandomState::new();
/// let v: Vec<u8> = vec![0xa8, 0x3c, 0x09]; /// let v: Vec<u8> = vec![0xa8, 0x3c, 0x09];
/// let s: &[u8] = &[0xa8, 0x3c, 0x09]; /// let s: &[u8] = &[0xa8, 0x3c, 0x09];
/// assert_eq!(b.hash_one(v), b.hash_one(s)); /// assert_eq!(b.hash_one(v), b.hash_one(s));

View File

@ -43,8 +43,7 @@
#![deny(fuzzy_provenance_casts)] #![deny(fuzzy_provenance_casts)]
#![deny(unsafe_op_in_unsafe_fn)] #![deny(unsafe_op_in_unsafe_fn)]
use std::collections::hash_map::DefaultHasher; use std::hash::{DefaultHasher, Hash, Hasher};
use std::hash::{Hash, Hasher};
mod arc; mod arc;
mod autotraits; mod autotraits;

View File

@ -297,7 +297,7 @@ impl<'a, T, const N: usize> TryFrom<&'a mut [T]> for &'a mut [T; N] {
/// ``` /// ```
/// use std::hash::BuildHasher; /// use std::hash::BuildHasher;
/// ///
/// let b = std::collections::hash_map::RandomState::new(); /// let b = std::hash::RandomState::new();
/// let a: [u8; 3] = [0xa8, 0x3c, 0x09]; /// let a: [u8; 3] = [0xa8, 0x3c, 0x09];
/// let s: &[u8] = &[0xa8, 0x3c, 0x09]; /// let s: &[u8] = &[0xa8, 0x3c, 0x09];
/// assert_eq!(b.hash_one(a), b.hash_one(s)); /// assert_eq!(b.hash_one(a), b.hash_one(s));

View File

@ -12,8 +12,7 @@
//! # Examples //! # Examples
//! //!
//! ```rust //! ```rust
//! use std::collections::hash_map::DefaultHasher; //! use std::hash::{DefaultHasher, Hash, Hasher};
//! use std::hash::{Hash, Hasher};
//! //!
//! #[derive(Hash)] //! #[derive(Hash)]
//! struct Person { //! struct Person {
@ -46,8 +45,7 @@
//! the [`Hash`] trait: //! the [`Hash`] trait:
//! //!
//! ```rust //! ```rust
//! use std::collections::hash_map::DefaultHasher; //! use std::hash::{DefaultHasher, Hash, Hasher};
//! use std::hash::{Hash, Hasher};
//! //!
//! struct Person { //! struct Person {
//! id: u32, //! id: u32,
@ -194,8 +192,7 @@ pub trait Hash {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::hash_map::DefaultHasher; /// use std::hash::{DefaultHasher, Hash, Hasher};
/// use std::hash::{Hash, Hasher};
/// ///
/// let mut hasher = DefaultHasher::new(); /// let mut hasher = DefaultHasher::new();
/// 7920.hash(&mut hasher); /// 7920.hash(&mut hasher);
@ -224,8 +221,7 @@ pub trait Hash {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::hash_map::DefaultHasher; /// use std::hash::{DefaultHasher, Hash, Hasher};
/// use std::hash::{Hash, Hasher};
/// ///
/// let mut hasher = DefaultHasher::new(); /// let mut hasher = DefaultHasher::new();
/// let numbers = [6, 28, 496, 8128]; /// let numbers = [6, 28, 496, 8128];
@ -300,8 +296,7 @@ pub use macros::Hash;
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::hash_map::DefaultHasher; /// use std::hash::{DefaultHasher, Hasher};
/// use std::hash::Hasher;
/// ///
/// let mut hasher = DefaultHasher::new(); /// let mut hasher = DefaultHasher::new();
/// ///
@ -329,8 +324,7 @@ pub trait Hasher {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::hash_map::DefaultHasher; /// use std::hash::{DefaultHasher, Hasher};
/// use std::hash::Hasher;
/// ///
/// let mut hasher = DefaultHasher::new(); /// let mut hasher = DefaultHasher::new();
/// hasher.write(b"Cool!"); /// hasher.write(b"Cool!");
@ -347,8 +341,7 @@ pub trait Hasher {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::hash_map::DefaultHasher; /// use std::hash::{DefaultHasher, Hasher};
/// use std::hash::Hasher;
/// ///
/// let mut hasher = DefaultHasher::new(); /// let mut hasher = DefaultHasher::new();
/// let data = [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]; /// let data = [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef];
@ -627,8 +620,7 @@ impl<H: Hasher + ?Sized> Hasher for &mut H {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::hash_map::RandomState; /// use std::hash::{BuildHasher, Hasher, RandomState};
/// use std::hash::{BuildHasher, Hasher};
/// ///
/// let s = RandomState::new(); /// let s = RandomState::new();
/// let mut hasher_1 = s.build_hasher(); /// let mut hasher_1 = s.build_hasher();
@ -656,8 +648,7 @@ pub trait BuildHasher {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::hash_map::RandomState; /// use std::hash::{BuildHasher, RandomState};
/// use std::hash::BuildHasher;
/// ///
/// let s = RandomState::new(); /// let s = RandomState::new();
/// let new_s = s.build_hasher(); /// let new_s = s.build_hasher();
@ -690,7 +681,7 @@ pub trait BuildHasher {
/// } /// }
/// ///
/// // Then later, in a `#[test]` for the type... /// // Then later, in a `#[test]` for the type...
/// let bh = std::collections::hash_map::RandomState::new(); /// let bh = std::hash::RandomState::new();
/// assert_eq!( /// assert_eq!(
/// bh.hash_one(OrderAmbivalentPair(1, 2)), /// bh.hash_one(OrderAmbivalentPair(1, 2)),
/// bh.hash_one(OrderAmbivalentPair(2, 1)) /// bh.hash_one(OrderAmbivalentPair(2, 1))

View File

@ -14,7 +14,7 @@ use crate::ptr;
/// ///
/// See: <https://131002.net/siphash> /// See: <https://131002.net/siphash>
#[unstable(feature = "hashmap_internals", issue = "none")] #[unstable(feature = "hashmap_internals", issue = "none")]
#[deprecated(since = "1.13.0", note = "use `std::collections::hash_map::DefaultHasher` instead")] #[deprecated(since = "1.13.0", note = "use `std::hash::DefaultHasher` instead")]
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
#[doc(hidden)] #[doc(hidden)]
pub struct SipHasher13 { pub struct SipHasher13 {
@ -25,7 +25,7 @@ pub struct SipHasher13 {
/// ///
/// See: <https://131002.net/siphash/> /// See: <https://131002.net/siphash/>
#[unstable(feature = "hashmap_internals", issue = "none")] #[unstable(feature = "hashmap_internals", issue = "none")]
#[deprecated(since = "1.13.0", note = "use `std::collections::hash_map::DefaultHasher` instead")] #[deprecated(since = "1.13.0", note = "use `std::hash::DefaultHasher` instead")]
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
struct SipHasher24 { struct SipHasher24 {
hasher: Hasher<Sip24Rounds>, hasher: Hasher<Sip24Rounds>,
@ -44,7 +44,7 @@ struct SipHasher24 {
/// it is not intended for cryptographic purposes. As such, all /// it is not intended for cryptographic purposes. As such, all
/// cryptographic uses of this implementation are _strongly discouraged_. /// cryptographic uses of this implementation are _strongly discouraged_.
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "1.13.0", note = "use `std::collections::hash_map::DefaultHasher` instead")] #[deprecated(since = "1.13.0", note = "use `std::hash::DefaultHasher` instead")]
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct SipHasher(SipHasher24); pub struct SipHasher(SipHasher24);
@ -147,10 +147,7 @@ impl SipHasher {
/// Creates a new `SipHasher` with the two initial keys set to 0. /// Creates a new `SipHasher` with the two initial keys set to 0.
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[deprecated( #[deprecated(since = "1.13.0", note = "use `std::hash::DefaultHasher` instead")]
since = "1.13.0",
note = "use `std::collections::hash_map::DefaultHasher` instead"
)]
#[rustc_const_unstable(feature = "const_hash", issue = "104061")] #[rustc_const_unstable(feature = "const_hash", issue = "104061")]
#[must_use] #[must_use]
pub const fn new() -> SipHasher { pub const fn new() -> SipHasher {
@ -160,10 +157,7 @@ impl SipHasher {
/// Creates a `SipHasher` that is keyed off the provided keys. /// Creates a `SipHasher` that is keyed off the provided keys.
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[deprecated( #[deprecated(since = "1.13.0", note = "use `std::hash::DefaultHasher` instead")]
since = "1.13.0",
note = "use `std::collections::hash_map::DefaultHasher` instead"
)]
#[rustc_const_unstable(feature = "const_hash", issue = "104061")] #[rustc_const_unstable(feature = "const_hash", issue = "104061")]
#[must_use] #[must_use]
pub const fn new_with_keys(key0: u64, key1: u64) -> SipHasher { pub const fn new_with_keys(key0: u64, key1: u64) -> SipHasher {
@ -175,10 +169,7 @@ impl SipHasher13 {
/// Creates a new `SipHasher13` with the two initial keys set to 0. /// Creates a new `SipHasher13` with the two initial keys set to 0.
#[inline] #[inline]
#[unstable(feature = "hashmap_internals", issue = "none")] #[unstable(feature = "hashmap_internals", issue = "none")]
#[deprecated( #[deprecated(since = "1.13.0", note = "use `std::hash::DefaultHasher` instead")]
since = "1.13.0",
note = "use `std::collections::hash_map::DefaultHasher` instead"
)]
#[rustc_const_unstable(feature = "const_hash", issue = "104061")] #[rustc_const_unstable(feature = "const_hash", issue = "104061")]
pub const fn new() -> SipHasher13 { pub const fn new() -> SipHasher13 {
SipHasher13::new_with_keys(0, 0) SipHasher13::new_with_keys(0, 0)
@ -187,10 +178,7 @@ impl SipHasher13 {
/// Creates a `SipHasher13` that is keyed off the provided keys. /// Creates a `SipHasher13` that is keyed off the provided keys.
#[inline] #[inline]
#[unstable(feature = "hashmap_internals", issue = "none")] #[unstable(feature = "hashmap_internals", issue = "none")]
#[deprecated( #[deprecated(since = "1.13.0", note = "use `std::hash::DefaultHasher` instead")]
since = "1.13.0",
note = "use `std::collections::hash_map::DefaultHasher` instead"
)]
#[rustc_const_unstable(feature = "const_hash", issue = "104061")] #[rustc_const_unstable(feature = "const_hash", issue = "104061")]
pub const 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) } SipHasher13 { hasher: Hasher::new_with_keys(key0, key1) }

View File

@ -1911,8 +1911,7 @@ pub fn addr_eq<T: ?Sized, U: ?Sized>(p: *const T, q: *const U) -> bool {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use std::collections::hash_map::DefaultHasher; /// use std::hash::{DefaultHasher, Hash, Hasher};
/// use std::hash::{Hash, Hasher};
/// use std::ptr; /// use std::ptr;
/// ///
/// let five = 5; /// let five = 5;

View File

@ -167,7 +167,7 @@ fn test_indirect_hasher() {
#[test] #[test]
fn test_build_hasher_object_safe() { fn test_build_hasher_object_safe() {
use std::collections::hash_map::{DefaultHasher, RandomState}; use std::hash::{DefaultHasher, RandomState};
let _: &dyn BuildHasher<Hasher = DefaultHasher> = &RandomState::new(); let _: &dyn BuildHasher<Hasher = DefaultHasher> = &RandomState::new();
} }

View File

@ -167,7 +167,7 @@ mod waker;
#[allow(dead_code)] // Not used in all configurations. #[allow(dead_code)] // Not used in all configurations.
pub(crate) fn test_rng() -> rand_xorshift::XorShiftRng { pub(crate) fn test_rng() -> rand_xorshift::XorShiftRng {
use core::hash::{BuildHasher, Hash, Hasher}; use core::hash::{BuildHasher, Hash, Hasher};
let mut hasher = std::collections::hash_map::RandomState::new().build_hasher(); let mut hasher = std::hash::RandomState::new().build_hasher();
core::panic::Location::caller().hash(&mut hasher); core::panic::Location::caller().hash(&mut hasher);
let hc64 = hasher.finish(); let hc64 = hasher.finish();
let seed_vec = hc64.to_le_bytes().into_iter().chain(0u8..8).collect::<Vec<u8>>(); let seed_vec = hc64.to_le_bytes().into_iter().chain(0u8..8).collect::<Vec<u8>>();

View File

@ -271,7 +271,7 @@ impl<K, V, S> HashMap<K, V, S> {
/// ///
/// ``` /// ```
/// use std::collections::HashMap; /// use std::collections::HashMap;
/// use std::collections::hash_map::RandomState; /// use std::hash::RandomState;
/// ///
/// let s = RandomState::new(); /// let s = RandomState::new();
/// let mut map = HashMap::with_hasher(s); /// let mut map = HashMap::with_hasher(s);
@ -303,7 +303,7 @@ impl<K, V, S> HashMap<K, V, S> {
/// ///
/// ``` /// ```
/// use std::collections::HashMap; /// use std::collections::HashMap;
/// use std::collections::hash_map::RandomState; /// use std::hash::RandomState;
/// ///
/// let s = RandomState::new(); /// let s = RandomState::new();
/// let mut map = HashMap::with_capacity_and_hasher(10, s); /// let mut map = HashMap::with_capacity_and_hasher(10, s);
@ -714,7 +714,7 @@ impl<K, V, S> HashMap<K, V, S> {
/// ///
/// ``` /// ```
/// use std::collections::HashMap; /// use std::collections::HashMap;
/// use std::collections::hash_map::RandomState; /// use std::hash::RandomState;
/// ///
/// let hasher = RandomState::new(); /// let hasher = RandomState::new();
/// let map: HashMap<i32, i32> = HashMap::with_hasher(hasher); /// let map: HashMap<i32, i32> = HashMap::with_hasher(hasher);

View File

@ -361,7 +361,7 @@ impl<T, S> HashSet<T, S> {
/// ///
/// ``` /// ```
/// use std::collections::HashSet; /// use std::collections::HashSet;
/// use std::collections::hash_map::RandomState; /// use std::hash::RandomState;
/// ///
/// let s = RandomState::new(); /// let s = RandomState::new();
/// let mut set = HashSet::with_hasher(s); /// let mut set = HashSet::with_hasher(s);
@ -393,7 +393,7 @@ impl<T, S> HashSet<T, S> {
/// ///
/// ``` /// ```
/// use std::collections::HashSet; /// use std::collections::HashSet;
/// use std::collections::hash_map::RandomState; /// use std::hash::RandomState;
/// ///
/// let s = RandomState::new(); /// let s = RandomState::new();
/// let mut set = HashSet::with_capacity_and_hasher(10, s); /// let mut set = HashSet::with_capacity_and_hasher(10, s);
@ -411,7 +411,7 @@ impl<T, S> HashSet<T, S> {
/// ///
/// ``` /// ```
/// use std::collections::HashSet; /// use std::collections::HashSet;
/// use std::collections::hash_map::RandomState; /// use std::hash::RandomState;
/// ///
/// let hasher = RandomState::new(); /// let hasher = RandomState::new();
/// let set: HashSet<i32> = HashSet::with_hasher(hasher); /// let set: HashSet<i32> = HashSet::with_hasher(hasher);

View File

@ -87,5 +87,5 @@ pub(crate) mod random;
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub use core::hash::*; pub use core::hash::*;
// #[stable(feature = "std_hash_exports", since = "CURRENT_RUSTC_VERSION")] #[stable(feature = "std_hash_exports", since = "CURRENT_RUSTC_VERSION")]
pub(crate) use self::random::{DefaultHasher, RandomState}; pub use self::random::{DefaultHasher, RandomState};

View File

@ -265,7 +265,7 @@ where
F: FnMut(TestEvent) -> io::Result<()>, F: FnMut(TestEvent) -> io::Result<()>,
{ {
use std::collections::HashMap; use std::collections::HashMap;
use std::hash::{DefaultHasher, BuildHasherDefault}; use std::hash::{BuildHasherDefault, DefaultHasher};
use std::sync::mpsc::RecvTimeoutError; use std::sync::mpsc::RecvTimeoutError;
struct RunningTest { struct RunningTest {
@ -286,8 +286,7 @@ where
} }
// Use a deterministic hasher // Use a deterministic hasher
type TestMap = type TestMap = HashMap<TestId, RunningTest, BuildHasherDefault<DefaultHasher>>;
HashMap<TestId, RunningTest, BuildHasherDefault<DefaultHasher>>;
struct TimeoutEntry { struct TimeoutEntry {
id: TestId, id: TestId,

View File

@ -20,12 +20,11 @@ use regex::{Captures, Regex};
use rustfix::{apply_suggestions, get_suggestions_from_json, Filter}; use rustfix::{apply_suggestions, get_suggestions_from_json, Filter};
use std::borrow::Cow; use std::borrow::Cow;
use std::collections::hash_map::DefaultHasher;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::env; use std::env;
use std::ffi::{OsStr, OsString}; use std::ffi::{OsStr, OsString};
use std::fs::{self, create_dir_all, File, OpenOptions}; use std::fs::{self, create_dir_all, File, OpenOptions};
use std::hash::{Hash, Hasher}; use std::hash::{DefaultHasher, Hash, Hasher};
use std::io::prelude::*; use std::io::prelude::*;
use std::io::{self, BufReader}; use std::io::{self, BufReader};
use std::iter; use std::iter;

View File

@ -1,7 +1,7 @@
use std::hash::BuildHasher; use std::hash::BuildHasher;
fn next_u64() -> u64 { fn next_u64() -> u64 {
let bh = std::collections::hash_map::RandomState::new(); let bh = std::hash::RandomState::new();
let h = bh.build_hasher(); let h = bh.build_hasher();
h.finish() //~ ERROR no method named `finish` found for struct `DefaultHasher` h.finish() //~ ERROR no method named `finish` found for struct `DefaultHasher`
} }