Skip to content

Commit

Permalink
Auto merge of #36815 - alexcrichton:stabilize-1.13, r=aturon
Browse files Browse the repository at this point in the history
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`

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
  • Loading branch information
bors authored Oct 3, 2016
2 parents ff71346 + 10c3134 commit 7a26aec
Show file tree
Hide file tree
Showing 24 changed files with 129 additions and 80 deletions.
4 changes: 4 additions & 0 deletions src/libcollections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ impl<T: Ord> BinaryHeap<T> {
///
/// ```
/// #![feature(binary_heap_extras)]
/// #![allow(deprecated)]
///
/// use std::collections::BinaryHeap;
/// let mut heap = BinaryHeap::new();
Expand All @@ -549,6 +550,7 @@ impl<T: Ord> BinaryHeap<T> {
#[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,
Expand All @@ -575,6 +577,7 @@ impl<T: Ord> BinaryHeap<T> {
///
/// ```
/// #![feature(binary_heap_extras)]
/// #![allow(deprecated)]
///
/// use std::collections::BinaryHeap;
/// let mut heap = BinaryHeap::new();
Expand All @@ -587,6 +590,7 @@ impl<T: Ord> BinaryHeap<T> {
#[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<T> {
if !self.is_empty() {
swap(&mut item, &mut self.data[0]);
Expand Down
3 changes: 3 additions & 0 deletions src/libcollectionstest/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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());
Expand Down
5 changes: 3 additions & 2 deletions src/libcollectionstest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -47,7 +48,7 @@ mod vec_deque;
mod vec;

fn hash<T: Hash>(t: &T) -> u64 {
let mut s = SipHasher::new();
let mut s = DefaultHasher::new();
t.hash(&mut s);
s.finish()
}
46 changes: 21 additions & 25 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<T>>,
#[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<T>>,
#[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)
}
Expand Down Expand Up @@ -573,8 +573,6 @@ impl<T: ?Sized> RefCell<T> {
/// # Examples
///
/// ```
/// #![feature(try_borrow)]
///
/// use std::cell::RefCell;
///
/// let c = RefCell::new(5);
Expand All @@ -589,15 +587,15 @@ impl<T: ?Sized> RefCell<T> {
/// 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<Ref<T>, BorrowError<T>> {
pub fn try_borrow(&self) -> Result<Ref<T>, 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: () }),
}
}

Expand Down Expand Up @@ -654,8 +652,6 @@ impl<T: ?Sized> RefCell<T> {
/// # Examples
///
/// ```
/// #![feature(try_borrow)]
///
/// use std::cell::RefCell;
///
/// let c = RefCell::new(5);
Expand All @@ -667,15 +663,15 @@ impl<T: ?Sized> RefCell<T> {
///
/// 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<RefMut<T>, BorrowMutError<T>> {
pub fn try_borrow_mut(&self) -> Result<RefMut<T>, 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: () }),
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/libcore/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion src/libcore/hash/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@

//! An implementation of SipHash.

#![allow(deprecated)]

use marker::PhantomData;
use ptr;

/// An implementation of SipHash 1-3.
///
/// 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<Sip13Rounds>,
Expand All @@ -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<Sip24Rounds>,
Expand All @@ -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);

Expand Down Expand Up @@ -136,30 +141,33 @@ 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)
}

/// 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)
}

/// 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)
Expand All @@ -171,13 +179,15 @@ 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)
}

/// 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)
Expand Down
12 changes: 3 additions & 9 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
if self.is_negative() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 3 additions & 0 deletions src/libcoretest/hash/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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};
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
}
Expand Down
Loading

0 comments on commit 7a26aec

Please sign in to comment.