From 10c3134da025f3d63700abf52769c0f106637a14 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 28 Sep 2016 17:23:36 -0700 Subject: [PATCH] std: Stabilize and deprecate APIs for 1.13 This commit is intended to be backported to the 1.13 branch, and works with the following APIs: Stabilized * `i32::checked_abs` * `i32::wrapping_abs` * `i32::overflowing_abs` * `RefCell::try_borrow` * `RefCell::try_borrow_mut` * `DefaultHasher` * `DefaultHasher::new` * `DefaultHasher::default` Deprecated * `BinaryHeap::push_pop` * `BinaryHeap::replace` * `SipHash13` * `SipHash24` * `SipHasher` - use `DefaultHasher` instead in the `std::collections::hash_map` module Closes #28147 Closes #34767 Closes #35057 Closes #35070 --- src/libcollections/binary_heap.rs | 4 ++ src/libcollectionstest/binary_heap.rs | 3 ++ src/libcollectionstest/lib.rs | 5 +- src/libcore/cell.rs | 46 +++++++++---------- src/libcore/hash/mod.rs | 2 + src/libcore/hash/sip.rs | 12 ++++- src/libcore/num/mod.rs | 12 ++--- src/libcoretest/hash/sip.rs | 3 ++ src/librustc/hir/map/definitions.rs | 5 +- src/librustc/session/config.rs | 22 +++++---- src/librustc/ty/util.rs | 5 +- src/librustc_bitflags/lib.rs | 5 +- src/librustc_incremental/calculate_svh/mod.rs | 9 ++-- .../calculate_svh/svh_visitor.rs | 7 +-- src/librustc_incremental/persist/fs.rs | 5 +- src/librustc_incremental/persist/save.rs | 5 +- src/librustc_save_analysis/dump_visitor.rs | 3 +- src/librustc_trans/partitioning.rs | 5 +- src/libstd/collections/hash/map.rs | 28 ++++++++++- src/libstd/error.rs | 8 ++-- src/libstd/ffi/c_str.rs | 7 +-- src/libstd/lib.rs | 1 - src/libstd/path.rs | 5 +- src/tools/cargotest/main.rs | 2 +- 24 files changed, 129 insertions(+), 80 deletions(-) diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 1fe921543bd4e..5f2401b2369e8 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -535,6 +535,7 @@ impl BinaryHeap { /// /// ``` /// #![feature(binary_heap_extras)] + /// #![allow(deprecated)] /// /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::new(); @@ -549,6 +550,7 @@ impl BinaryHeap { #[unstable(feature = "binary_heap_extras", reason = "needs to be audited", issue = "28147")] + #[rustc_deprecated(since = "1.13.0", reason = "use `peek_mut` instead")] pub fn push_pop(&mut self, mut item: T) -> T { match self.data.get_mut(0) { None => return item, @@ -575,6 +577,7 @@ impl BinaryHeap { /// /// ``` /// #![feature(binary_heap_extras)] + /// #![allow(deprecated)] /// /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::new(); @@ -587,6 +590,7 @@ impl BinaryHeap { #[unstable(feature = "binary_heap_extras", reason = "needs to be audited", issue = "28147")] + #[rustc_deprecated(since = "1.13.0", reason = "use `peek_mut` instead")] pub fn replace(&mut self, mut item: T) -> Option { if !self.is_empty() { swap(&mut item, &mut self.data[0]); diff --git a/src/libcollectionstest/binary_heap.rs b/src/libcollectionstest/binary_heap.rs index e2a57bd8d3862..faabcf4c372b6 100644 --- a/src/libcollectionstest/binary_heap.rs +++ b/src/libcollectionstest/binary_heap.rs @@ -139,6 +139,7 @@ fn test_push_unique() { } #[test] +#[allow(deprecated)] fn test_push_pop() { let mut heap = BinaryHeap::from(vec![5, 5, 2, 1, 3]); assert_eq!(heap.len(), 5); @@ -153,6 +154,7 @@ fn test_push_pop() { } #[test] +#[allow(deprecated)] fn test_replace() { let mut heap = BinaryHeap::from(vec![5, 5, 2, 1, 3]); assert_eq!(heap.len(), 5); @@ -212,6 +214,7 @@ fn test_empty_peek_mut() { } #[test] +#[allow(deprecated)] fn test_empty_replace() { let mut heap = BinaryHeap::new(); assert!(heap.replace(5).is_none()); diff --git a/src/libcollectionstest/lib.rs b/src/libcollectionstest/lib.rs index 878581a4f296e..950e6ee2e9ef0 100644 --- a/src/libcollectionstest/lib.rs +++ b/src/libcollectionstest/lib.rs @@ -31,7 +31,8 @@ extern crate collections; extern crate test; extern crate rustc_unicode; -use std::hash::{Hash, Hasher, SipHasher}; +use std::hash::{Hash, Hasher}; +use std::collections::hash_map::DefaultHasher; #[cfg(test)] #[macro_use] mod bench; @@ -47,7 +48,7 @@ mod vec_deque; mod vec; fn hash(t: &T) -> u64 { - let mut s = SipHasher::new(); + let mut s = DefaultHasher::new(); t.hash(&mut s); s.finish() } diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 51221f1b9b9e9..64a7a8c5ef785 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -175,7 +175,7 @@ use cmp::Ordering; use fmt::{self, Debug, Display}; -use marker::{PhantomData, Unsize}; +use marker::Unsize; use ops::{Deref, DerefMut, CoerceUnsized}; /// A mutable memory location that admits only `Copy` data. @@ -403,40 +403,40 @@ pub enum BorrowState { } /// An error returned by [`RefCell::try_borrow`](struct.RefCell.html#method.try_borrow). -#[unstable(feature = "try_borrow", issue = "35070")] -pub struct BorrowError<'a, T: 'a + ?Sized> { - marker: PhantomData<&'a RefCell>, +#[stable(feature = "try_borrow", since = "1.13.0")] +pub struct BorrowError { + _private: (), } -#[unstable(feature = "try_borrow", issue = "35070")] -impl<'a, T: ?Sized> Debug for BorrowError<'a, T> { +#[stable(feature = "try_borrow", since = "1.13.0")] +impl Debug for BorrowError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("BorrowError").finish() } } -#[unstable(feature = "try_borrow", issue = "35070")] -impl<'a, T: ?Sized> Display for BorrowError<'a, T> { +#[stable(feature = "try_borrow", since = "1.13.0")] +impl Display for BorrowError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { Display::fmt("already mutably borrowed", f) } } /// An error returned by [`RefCell::try_borrow_mut`](struct.RefCell.html#method.try_borrow_mut). -#[unstable(feature = "try_borrow", issue = "35070")] -pub struct BorrowMutError<'a, T: 'a + ?Sized> { - marker: PhantomData<&'a RefCell>, +#[stable(feature = "try_borrow", since = "1.13.0")] +pub struct BorrowMutError { + _private: (), } -#[unstable(feature = "try_borrow", issue = "35070")] -impl<'a, T: ?Sized> Debug for BorrowMutError<'a, T> { +#[stable(feature = "try_borrow", since = "1.13.0")] +impl Debug for BorrowMutError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("BorrowMutError").finish() } } -#[unstable(feature = "try_borrow", issue = "35070")] -impl<'a, T: ?Sized> Display for BorrowMutError<'a, T> { +#[stable(feature = "try_borrow", since = "1.13.0")] +impl Display for BorrowMutError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { Display::fmt("already borrowed", f) } @@ -573,8 +573,6 @@ impl RefCell { /// # Examples /// /// ``` - /// #![feature(try_borrow)] - /// /// use std::cell::RefCell; /// /// let c = RefCell::new(5); @@ -589,15 +587,15 @@ impl RefCell { /// assert!(c.try_borrow().is_ok()); /// } /// ``` - #[unstable(feature = "try_borrow", issue = "35070")] + #[stable(feature = "try_borrow", since = "1.13.0")] #[inline] - pub fn try_borrow(&self) -> Result, BorrowError> { + pub fn try_borrow(&self) -> Result, BorrowError> { match BorrowRef::new(&self.borrow) { Some(b) => Ok(Ref { value: unsafe { &*self.value.get() }, borrow: b, }), - None => Err(BorrowError { marker: PhantomData }), + None => Err(BorrowError { _private: () }), } } @@ -654,8 +652,6 @@ impl RefCell { /// # Examples /// /// ``` - /// #![feature(try_borrow)] - /// /// use std::cell::RefCell; /// /// let c = RefCell::new(5); @@ -667,15 +663,15 @@ impl RefCell { /// /// assert!(c.try_borrow_mut().is_ok()); /// ``` - #[unstable(feature = "try_borrow", issue = "35070")] + #[stable(feature = "try_borrow", since = "1.13.0")] #[inline] - pub fn try_borrow_mut(&self) -> Result, BorrowMutError> { + pub fn try_borrow_mut(&self) -> Result, BorrowMutError> { match BorrowRefMut::new(&self.borrow) { Some(b) => Ok(RefMut { value: unsafe { &mut *self.value.get() }, borrow: b, }), - None => Err(BorrowMutError { marker: PhantomData }), + None => Err(BorrowMutError { _private: () }), } } diff --git a/src/libcore/hash/mod.rs b/src/libcore/hash/mod.rs index 081f0c14ec30c..6a60cfcc12084 100644 --- a/src/libcore/hash/mod.rs +++ b/src/libcore/hash/mod.rs @@ -76,9 +76,11 @@ use marker; use mem; #[stable(feature = "rust1", since = "1.0.0")] +#[allow(deprecated)] pub use self::sip::SipHasher; #[unstable(feature = "sip_hash_13", issue = "29754")] +#[allow(deprecated)] pub use self::sip::{SipHasher13, SipHasher24}; mod sip; diff --git a/src/libcore/hash/sip.rs b/src/libcore/hash/sip.rs index dc53683d6337c..bf138a45de866 100644 --- a/src/libcore/hash/sip.rs +++ b/src/libcore/hash/sip.rs @@ -10,6 +10,8 @@ //! An implementation of SipHash. +#![allow(deprecated)] + use marker::PhantomData; use ptr; @@ -17,6 +19,7 @@ use ptr; /// /// See: https://131002.net/siphash/ #[unstable(feature = "sip_hash_13", issue = "34767")] +#[rustc_deprecated(since = "1.13.0", reason = "use `DefaultHasher` instead")] #[derive(Debug, Clone, Default)] pub struct SipHasher13 { hasher: Hasher, @@ -26,6 +29,7 @@ pub struct SipHasher13 { /// /// See: https://131002.net/siphash/ #[unstable(feature = "sip_hash_13", issue = "34767")] +#[rustc_deprecated(since = "1.13.0", reason = "use `DefaultHasher` instead")] #[derive(Debug, Clone, Default)] pub struct SipHasher24 { hasher: Hasher, @@ -47,6 +51,7 @@ pub struct SipHasher24 { /// it is not intended for cryptographic purposes. As such, all /// cryptographic uses of this implementation are _strongly discouraged_. #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated(since = "1.13.0", reason = "use `DefaultHasher` instead")] #[derive(Debug, Clone, Default)] pub struct SipHasher(SipHasher24); @@ -136,6 +141,7 @@ impl SipHasher { /// Creates a new `SipHasher` with the two initial keys set to 0. #[inline] #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_deprecated(since = "1.13.0", reason = "use `DefaultHasher` instead")] pub fn new() -> SipHasher { SipHasher::new_with_keys(0, 0) } @@ -143,16 +149,17 @@ impl SipHasher { /// Creates a `SipHasher` that is keyed off the provided keys. #[inline] #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_deprecated(since = "1.13.0", reason = "use `DefaultHasher` instead")] pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher { SipHasher(SipHasher24::new_with_keys(key0, key1)) } } - impl SipHasher13 { /// Creates a new `SipHasher13` with the two initial keys set to 0. #[inline] #[unstable(feature = "sip_hash_13", issue = "34767")] + #[rustc_deprecated(since = "1.13.0", reason = "use `DefaultHasher` instead")] pub fn new() -> SipHasher13 { SipHasher13::new_with_keys(0, 0) } @@ -160,6 +167,7 @@ impl SipHasher13 { /// Creates a `SipHasher13` that is keyed off the provided keys. #[inline] #[unstable(feature = "sip_hash_13", issue = "34767")] + #[rustc_deprecated(since = "1.13.0", reason = "use `DefaultHasher` instead")] pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher13 { SipHasher13 { hasher: Hasher::new_with_keys(key0, key1) @@ -171,6 +179,7 @@ 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 `DefaultHasher` instead")] pub fn new() -> SipHasher24 { SipHasher24::new_with_keys(0, 0) } @@ -178,6 +187,7 @@ impl SipHasher24 { /// 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 `DefaultHasher` instead")] pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher24 { SipHasher24 { hasher: Hasher::new_with_keys(key0, key1) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 7b797631dfd57..386daa08468c7 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -613,14 +613,12 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` - /// # #![feature(no_panic_abs)] - /// /// use std::i32; /// /// assert_eq!((-5i32).checked_abs(), Some(5)); /// assert_eq!(i32::MIN.checked_abs(), None); /// ``` - #[unstable(feature = "no_panic_abs", issue = "35057")] + #[stable(feature = "no_panic_abs", since = "1.13.0")] #[inline] pub fn checked_abs(self) -> Option { if self.is_negative() { @@ -895,14 +893,12 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` - /// # #![feature(no_panic_abs)] - /// /// assert_eq!(100i8.wrapping_abs(), 100); /// assert_eq!((-100i8).wrapping_abs(), 100); /// assert_eq!((-128i8).wrapping_abs(), -128); /// assert_eq!((-128i8).wrapping_abs() as u8, 128); /// ``` - #[unstable(feature = "no_panic_abs", issue = "35057")] + #[stable(feature = "no_panic_abs", since = "1.13.0")] #[inline(always)] pub fn wrapping_abs(self) -> Self { if self.is_negative() { @@ -1133,13 +1129,11 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` - /// # #![feature(no_panic_abs)] - /// /// assert_eq!(10i8.overflowing_abs(), (10,false)); /// assert_eq!((-10i8).overflowing_abs(), (10,false)); /// assert_eq!((-128i8).overflowing_abs(), (-128,true)); /// ``` - #[unstable(feature = "no_panic_abs", issue = "35057")] + #[stable(feature = "no_panic_abs", since = "1.13.0")] #[inline] pub fn overflowing_abs(self) -> (Self, bool) { if self.is_negative() { diff --git a/src/libcoretest/hash/sip.rs b/src/libcoretest/hash/sip.rs index a5e6005545bd7..b465d7de180af 100644 --- a/src/libcoretest/hash/sip.rs +++ b/src/libcoretest/hash/sip.rs @@ -7,6 +7,9 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. + +#![allow(deprecated)] + use test::{Bencher, black_box}; use core::hash::{Hash, Hasher}; diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs index f87844652cc19..e8b3714bbe3b8 100644 --- a/src/librustc/hir/map/definitions.rs +++ b/src/librustc/hir/map/definitions.rs @@ -11,7 +11,8 @@ use hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE}; use rustc_data_structures::fnv::FnvHashMap; use std::fmt::Write; -use std::hash::{Hash, Hasher, SipHasher}; +use std::hash::{Hash, Hasher}; +use std::collections::hash_map::DefaultHasher; use syntax::ast; use syntax::parse::token::{self, InternedString}; use ty::TyCtxt; @@ -130,7 +131,7 @@ impl DefPath { } pub fn deterministic_hash(&self, tcx: TyCtxt) -> u64 { - let mut state = SipHasher::new(); + let mut state = DefaultHasher::new(); self.deterministic_hash_to(tcx, &mut state); state.finish() } diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index f8b06bf2e9762..f4fd481606c7a 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -39,7 +39,8 @@ use std::collections::btree_map::Keys as BTreeMapKeysIter; use std::collections::btree_map::Values as BTreeMapValuesIter; use std::fmt; -use std::hash::{Hasher, SipHasher}; +use std::hash::Hasher; +use std::collections::hash_map::DefaultHasher; use std::iter::FromIterator; use std::path::PathBuf; @@ -212,7 +213,7 @@ macro_rules! top_level_options { $warn_text, self.error_format)*]); })* - let mut hasher = SipHasher::new(); + let mut hasher = DefaultHasher::new(); dep_tracking::stable_hash(sub_hashes, &mut hasher, self.error_format); @@ -566,7 +567,7 @@ macro_rules! options { impl<'a> dep_tracking::DepTrackingHash for $struct_name { - fn hash(&self, hasher: &mut SipHasher, error_format: ErrorOutputType) { + fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) { let mut sub_hashes = BTreeMap::new(); $({ hash_option!($opt, @@ -1650,21 +1651,22 @@ mod dep_tracking { use middle::cstore; use session::search_paths::{PathKind, SearchPaths}; use std::collections::BTreeMap; - use std::hash::{Hash, SipHasher}; + use std::hash::Hash; use std::path::PathBuf; + use std::collections::hash_map::DefaultHasher; use super::{Passes, CrateType, OptLevel, DebugInfoLevel, OutputTypes, Externs, ErrorOutputType}; use syntax::feature_gate::UnstableFeatures; use rustc_back::PanicStrategy; pub trait DepTrackingHash { - fn hash(&self, &mut SipHasher, ErrorOutputType); + fn hash(&self, &mut DefaultHasher, ErrorOutputType); } macro_rules! impl_dep_tracking_hash_via_hash { ($t:ty) => ( impl DepTrackingHash for $t { - fn hash(&self, hasher: &mut SipHasher, _: ErrorOutputType) { + fn hash(&self, hasher: &mut DefaultHasher, _: ErrorOutputType) { Hash::hash(self, hasher); } } @@ -1674,7 +1676,7 @@ mod dep_tracking { macro_rules! impl_dep_tracking_hash_for_sortable_vec_of { ($t:ty) => ( impl DepTrackingHash for Vec<$t> { - fn hash(&self, hasher: &mut SipHasher, error_format: ErrorOutputType) { + fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) { let mut elems: Vec<&$t> = self.iter().collect(); elems.sort(); Hash::hash(&elems.len(), hasher); @@ -1713,7 +1715,7 @@ mod dep_tracking { impl_dep_tracking_hash_for_sortable_vec_of!((String, cstore::NativeLibraryKind)); impl DepTrackingHash for SearchPaths { - fn hash(&self, hasher: &mut SipHasher, _: ErrorOutputType) { + fn hash(&self, hasher: &mut DefaultHasher, _: ErrorOutputType) { let mut elems: Vec<_> = self .iter(PathKind::All) .collect(); @@ -1726,7 +1728,7 @@ mod dep_tracking { where T1: DepTrackingHash, T2: DepTrackingHash { - fn hash(&self, hasher: &mut SipHasher, error_format: ErrorOutputType) { + fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) { Hash::hash(&0, hasher); DepTrackingHash::hash(&self.0, hasher, error_format); Hash::hash(&1, hasher); @@ -1736,7 +1738,7 @@ mod dep_tracking { // This is a stable hash because BTreeMap is a sorted container pub fn stable_hash(sub_hashes: BTreeMap<&'static str, &DepTrackingHash>, - hasher: &mut SipHasher, + hasher: &mut DefaultHasher, error_format: ErrorOutputType) { for (key, sub_hash) in sub_hashes { // Using Hash::hash() instead of DepTrackingHash::hash() is fine for diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index 8fe5756a60ecb..c2d8a1aa0638f 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -23,7 +23,8 @@ use ty::TypeVariants::*; use rustc_const_math::{ConstInt, ConstIsize, ConstUsize}; use std::cmp; -use std::hash::{Hash, SipHasher, Hasher}; +use std::hash::{Hash, Hasher}; +use std::collections::hash_map::DefaultHasher; use std::intrinsics; use syntax::ast::{self, Name}; use syntax::attr::{self, SignedInt, UnsignedInt}; @@ -352,7 +353,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// Creates a hash of the type `Ty` which will be the same no matter what crate /// context it's calculated within. This is used by the `type_id` intrinsic. pub fn type_id_hash(self, ty: Ty<'tcx>) -> u64 { - let mut hasher = TypeIdHasher::new(self, SipHasher::new()); + let mut hasher = TypeIdHasher::new(self, DefaultHasher::default()); hasher.visit_ty(ty); hasher.finish() } diff --git a/src/librustc_bitflags/lib.rs b/src/librustc_bitflags/lib.rs index 7e96adfc4bdbc..e65d112430a16 100644 --- a/src/librustc_bitflags/lib.rs +++ b/src/librustc_bitflags/lib.rs @@ -291,7 +291,8 @@ macro_rules! bitflags { #[cfg(test)] #[allow(non_upper_case_globals)] mod tests { - use std::hash::{Hash, Hasher, SipHasher}; + use std::hash::{Hash, Hasher}; + use std::collections::hash_map::DefaultHasher; use std::option::Option::{None, Some}; bitflags! { @@ -492,7 +493,7 @@ mod tests { } fn hash(t: &T) -> u64 { - let mut s = SipHasher::new(); + let mut s = DefaultHasher::new(); t.hash(&mut s); s.finish() } diff --git a/src/librustc_incremental/calculate_svh/mod.rs b/src/librustc_incremental/calculate_svh/mod.rs index 92ed2637c3d1f..a22b51ac04461 100644 --- a/src/librustc_incremental/calculate_svh/mod.rs +++ b/src/librustc_incremental/calculate_svh/mod.rs @@ -29,7 +29,8 @@ use syntax::ast; use std::cell::RefCell; -use std::hash::{Hash, SipHasher, Hasher}; +use std::hash::{Hash, Hasher}; +use std::collections::hash_map::DefaultHasher; use rustc::dep_graph::DepNode; use rustc::hir; use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId}; @@ -126,9 +127,9 @@ impl<'a, 'tcx> HashItemsVisitor<'a, 'tcx> { { assert!(def_id.is_local()); debug!("HashItemsVisitor::calculate(def_id={:?})", def_id); - // FIXME: this should use SHA1, not SipHash. SipHash is not + // FIXME: this should use SHA1, not DefaultHasher. DefaultHasher is not // built to avoid collisions. - let mut state = SipHasher::new(); + let mut state = DefaultHasher::new(); walk_op(&mut StrictVersionHashVisitor::new(&mut state, self.tcx, &mut self.def_path_hashes, @@ -142,7 +143,7 @@ impl<'a, 'tcx> HashItemsVisitor<'a, 'tcx> { fn compute_crate_hash(&mut self) { let krate = self.tcx.map.krate(); - let mut crate_state = SipHasher::new(); + let mut crate_state = DefaultHasher::new(); let crate_disambiguator = self.tcx.sess.local_crate_disambiguator(); "crate_disambiguator".hash(&mut crate_state); diff --git a/src/librustc_incremental/calculate_svh/svh_visitor.rs b/src/librustc_incremental/calculate_svh/svh_visitor.rs index 55fe5fc1e349a..0cd5ae6845afa 100644 --- a/src/librustc_incremental/calculate_svh/svh_visitor.rs +++ b/src/librustc_incremental/calculate_svh/svh_visitor.rs @@ -25,7 +25,8 @@ use rustc::hir::def_id::DefId; use rustc::hir::intravisit as visit; use rustc::ty::TyCtxt; use rustc_data_structures::fnv; -use std::hash::{Hash, SipHasher}; +use std::hash::Hash; +use std::collections::hash_map::DefaultHasher; use super::def_path_hash::DefPathHashes; use super::caching_codemap_view::CachingCodemapView; @@ -42,7 +43,7 @@ const IGNORED_ATTRIBUTES: &'static [&'static str] = &[ pub struct StrictVersionHashVisitor<'a, 'hash: 'a, 'tcx: 'hash> { pub tcx: TyCtxt<'hash, 'tcx, 'tcx>, - pub st: &'a mut SipHasher, + pub st: &'a mut DefaultHasher, // collect a deterministic hash of def-ids that we have seen def_path_hashes: &'a mut DefPathHashes<'hash, 'tcx>, hash_spans: bool, @@ -50,7 +51,7 @@ pub struct StrictVersionHashVisitor<'a, 'hash: 'a, 'tcx: 'hash> { } impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> { - pub fn new(st: &'a mut SipHasher, + pub fn new(st: &'a mut DefaultHasher, tcx: TyCtxt<'hash, 'tcx, 'tcx>, def_path_hashes: &'a mut DefPathHashes<'hash, 'tcx>, codemap: &'a mut CachingCodemapView<'tcx>, diff --git a/src/librustc_incremental/persist/fs.rs b/src/librustc_incremental/persist/fs.rs index 2d28afeaebf2d..428283309b001 100644 --- a/src/librustc_incremental/persist/fs.rs +++ b/src/librustc_incremental/persist/fs.rs @@ -656,13 +656,14 @@ fn crate_path(sess: &Session, crate_name: &str, crate_disambiguator: &str) -> PathBuf { - use std::hash::{SipHasher, Hasher, Hash}; + use std::hash::{Hasher, Hash}; + use std::collections::hash_map::DefaultHasher; let incr_dir = sess.opts.incremental.as_ref().unwrap().clone(); // The full crate disambiguator is really long. A hash of it should be // sufficient. - let mut hasher = SipHasher::new(); + let mut hasher = DefaultHasher::new(); crate_disambiguator.hash(&mut hasher); let crate_name = format!("{}-{}", crate_name, encode_base_36(hasher.finish())); diff --git a/src/librustc_incremental/persist/save.rs b/src/librustc_incremental/persist/save.rs index e6fb1da1982c1..bc542b71ac670 100644 --- a/src/librustc_incremental/persist/save.rs +++ b/src/librustc_incremental/persist/save.rs @@ -16,10 +16,11 @@ use rustc::ty::TyCtxt; use rustc_data_structures::fnv::FnvHashMap; use rustc_serialize::Encodable as RustcEncodable; use rustc_serialize::opaque::Encoder; -use std::hash::{Hash, Hasher, SipHasher}; +use std::hash::{Hash, Hasher}; use std::io::{self, Cursor, Write}; use std::fs::{self, File}; use std::path::PathBuf; +use std::collections::hash_map::DefaultHasher; use IncrementalHashesMap; use super::data::*; @@ -241,7 +242,7 @@ pub fn encode_metadata_hashes(tcx: TyCtxt, .collect(); hashes.sort(); - let mut state = SipHasher::new(); + let mut state = DefaultHasher::new(); hashes.hash(&mut state); let hash = state.finish(); diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 79fcff7d8a166..0869ad168bced 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -35,6 +35,7 @@ use rustc::session::Session; use rustc::ty::{self, TyCtxt, ImplOrTraitItem, ImplOrTraitItemContainer}; use std::collections::HashSet; +use std::collections::hash_map::DefaultHasher; use std::hash::*; use syntax::ast::{self, NodeId, PatKind, Attribute, CRATE_NODE_ID}; @@ -1064,7 +1065,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { None => return, Some(data) => data, }; - let mut hasher = SipHasher::new(); + let mut hasher = DefaultHasher::new(); data.callee_span.hash(&mut hasher); let hash = hasher.finish(); let qualname = format!("{}::{}", data.name, hash); diff --git a/src/librustc_trans/partitioning.rs b/src/librustc_trans/partitioning.rs index 65615e6b6440c..180ab5528030f 100644 --- a/src/librustc_trans/partitioning.rs +++ b/src/librustc_trans/partitioning.rs @@ -127,8 +127,9 @@ use rustc::session::config::NUMBERED_CODEGEN_UNIT_MARKER; use rustc::ty::TyCtxt; use rustc::ty::item_path::characteristic_def_id_of_type; use std::cmp::Ordering; -use std::hash::{Hash, Hasher, SipHasher}; +use std::hash::{Hash, Hasher}; use std::sync::Arc; +use std::collections::hash_map::DefaultHasher; use symbol_map::SymbolMap; use syntax::ast::NodeId; use syntax::parse::token::{self, InternedString}; @@ -188,7 +189,7 @@ impl<'tcx> CodegenUnit<'tcx> { } pub fn compute_symbol_name_hash(&self, tcx: TyCtxt, symbol_map: &SymbolMap) -> u64 { - let mut state = SipHasher::new(); + let mut state = DefaultHasher::new(); let all_items = self.items_in_deterministic_order(tcx, symbol_map); for (item, _) in all_items { let symbol_name = symbol_map.get(item).unwrap(); diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 35f5641679afa..c5f2f8f3463c9 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -14,6 +14,7 @@ use self::VacantEntryState::*; use borrow::Borrow; use cmp::max; use fmt::{self, Debug}; +#[allow(deprecated)] use hash::{Hash, Hasher, BuildHasher, SipHasher13}; use iter::{FromIterator, FusedIterator}; use mem::{self, replace}; @@ -2013,6 +2014,7 @@ impl RandomState { impl BuildHasher for RandomState { type Hasher = DefaultHasher; #[inline] + #[allow(deprecated)] fn build_hasher(&self) -> DefaultHasher { DefaultHasher(SipHasher13::new_with_keys(self.k0, self.k1)) } @@ -2025,10 +2027,32 @@ impl BuildHasher for RandomState { /// /// [`RandomState`]: struct.RandomState.html /// [`Hasher`]: ../../hash/trait.Hasher.html -#[unstable(feature = "hashmap_default_hasher", issue = "0")] +#[stable(feature = "hashmap_default_hasher", since = "1.13.0")] +#[allow(deprecated)] +#[derive(Debug)] pub struct DefaultHasher(SipHasher13); -#[unstable(feature = "hashmap_default_hasher", issue = "0")] +impl DefaultHasher { + /// Creates a new `DefaultHasher`. + /// + /// This hasher is not guaranteed to be the same as all other + /// `DefaultHasher` instances, but is the same as all other `DefaultHasher` + /// instances created through `new` or `default`. + #[stable(feature = "hashmap_default_hasher", since = "1.13.0")] + #[allow(deprecated)] + pub fn new() -> DefaultHasher { + DefaultHasher(SipHasher13::new_with_keys(0, 0)) + } +} + +#[stable(feature = "hashmap_default_hasher", since = "1.13.0")] +impl Default for DefaultHasher { + fn default() -> DefaultHasher { + DefaultHasher::new() + } +} + +#[stable(feature = "hashmap_default_hasher", since = "1.13.0")] impl Hasher for DefaultHasher { #[inline] fn write(&mut self, msg: &[u8]) { diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 1629062001003..87092b1abc92a 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -288,15 +288,15 @@ impl Error for fmt::Error { } } -#[unstable(feature = "try_borrow", issue = "35070")] -impl<'a, T: ?Sized + Reflect> Error for cell::BorrowError<'a, T> { +#[stable(feature = "try_borrow", since = "1.13.0")] +impl Error for cell::BorrowError { fn description(&self) -> &str { "already mutably borrowed" } } -#[unstable(feature = "try_borrow", issue = "35070")] -impl<'a, T: ?Sized + Reflect> Error for cell::BorrowMutError<'a, T> { +#[stable(feature = "try_borrow", since = "1.13.0")] +impl Error for cell::BorrowMutError { fn description(&self) -> &str { "already borrowed" } diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 6f5ce350e6cb3..3ad5b5627d319 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -726,7 +726,8 @@ mod tests { use super::*; use os::raw::c_char; use borrow::Cow::{Borrowed, Owned}; - use hash::{SipHasher, Hash, Hasher}; + use hash::{Hash, Hasher}; + use collections::hash_map::DefaultHasher; #[test] fn c_to_rust() { @@ -808,10 +809,10 @@ mod tests { let ptr = data.as_ptr() as *const c_char; let cstr: &'static CStr = unsafe { CStr::from_ptr(ptr) }; - let mut s = SipHasher::new_with_keys(0, 0); + let mut s = DefaultHasher::new(); cstr.hash(&mut s); let cstr_hash = s.finish(); - let mut s = SipHasher::new_with_keys(0, 0); + let mut s = DefaultHasher::new(); CString::new(&data[..data.len() - 1]).unwrap().hash(&mut s); let cstring_hash = s.finish(); diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index b3e4351e9b200..eee8579884125 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -273,7 +273,6 @@ #![feature(str_utf16)] #![feature(test, rustc_private)] #![feature(thread_local)] -#![feature(try_borrow)] #![feature(try_from)] #![feature(unboxed_closures)] #![feature(unicode)] diff --git a/src/libstd/path.rs b/src/libstd/path.rs index bd27bcf48a09d..d625934133b2f 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -3511,10 +3511,11 @@ mod tests { #[test] pub fn test_compare() { - use hash::{Hash, Hasher, SipHasher}; + use hash::{Hash, Hasher}; + use collections::hash_map::DefaultHasher; fn hash(t: T) -> u64 { - let mut s = SipHasher::new_with_keys(0, 0); + let mut s = DefaultHasher::new(); t.hash(&mut s); s.finish() } diff --git a/src/tools/cargotest/main.rs b/src/tools/cargotest/main.rs index acf12dab16aff..354cce691270a 100644 --- a/src/tools/cargotest/main.rs +++ b/src/tools/cargotest/main.rs @@ -24,7 +24,7 @@ struct Test { const TEST_REPOS: &'static [Test] = &[Test { name: "cargo", repo: "https://github.com/rust-lang/cargo", - sha: "2d85908217f99a30aa5f68e05a8980704bb71fad", + sha: "d8936af1390ab0844e5e68b459214f2529c9f647", lock: None, }, Test {