Skip to content

Commit 7a26aec

Browse files
authored
Auto merge of #36815 - alexcrichton:stabilize-1.13, r=aturon
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
2 parents ff71346 + 10c3134 commit 7a26aec

File tree

24 files changed

+129
-80
lines changed

24 files changed

+129
-80
lines changed

src/libcollections/binary_heap.rs

+4
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ impl<T: Ord> BinaryHeap<T> {
535535
///
536536
/// ```
537537
/// #![feature(binary_heap_extras)]
538+
/// #![allow(deprecated)]
538539
///
539540
/// use std::collections::BinaryHeap;
540541
/// let mut heap = BinaryHeap::new();
@@ -549,6 +550,7 @@ impl<T: Ord> BinaryHeap<T> {
549550
#[unstable(feature = "binary_heap_extras",
550551
reason = "needs to be audited",
551552
issue = "28147")]
553+
#[rustc_deprecated(since = "1.13.0", reason = "use `peek_mut` instead")]
552554
pub fn push_pop(&mut self, mut item: T) -> T {
553555
match self.data.get_mut(0) {
554556
None => return item,
@@ -575,6 +577,7 @@ impl<T: Ord> BinaryHeap<T> {
575577
///
576578
/// ```
577579
/// #![feature(binary_heap_extras)]
580+
/// #![allow(deprecated)]
578581
///
579582
/// use std::collections::BinaryHeap;
580583
/// let mut heap = BinaryHeap::new();
@@ -587,6 +590,7 @@ impl<T: Ord> BinaryHeap<T> {
587590
#[unstable(feature = "binary_heap_extras",
588591
reason = "needs to be audited",
589592
issue = "28147")]
593+
#[rustc_deprecated(since = "1.13.0", reason = "use `peek_mut` instead")]
590594
pub fn replace(&mut self, mut item: T) -> Option<T> {
591595
if !self.is_empty() {
592596
swap(&mut item, &mut self.data[0]);

src/libcollectionstest/binary_heap.rs

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ fn test_push_unique() {
139139
}
140140

141141
#[test]
142+
#[allow(deprecated)]
142143
fn test_push_pop() {
143144
let mut heap = BinaryHeap::from(vec![5, 5, 2, 1, 3]);
144145
assert_eq!(heap.len(), 5);
@@ -153,6 +154,7 @@ fn test_push_pop() {
153154
}
154155

155156
#[test]
157+
#[allow(deprecated)]
156158
fn test_replace() {
157159
let mut heap = BinaryHeap::from(vec![5, 5, 2, 1, 3]);
158160
assert_eq!(heap.len(), 5);
@@ -212,6 +214,7 @@ fn test_empty_peek_mut() {
212214
}
213215

214216
#[test]
217+
#[allow(deprecated)]
215218
fn test_empty_replace() {
216219
let mut heap = BinaryHeap::new();
217220
assert!(heap.replace(5).is_none());

src/libcollectionstest/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ extern crate collections;
3131
extern crate test;
3232
extern crate rustc_unicode;
3333

34-
use std::hash::{Hash, Hasher, SipHasher};
34+
use std::hash::{Hash, Hasher};
35+
use std::collections::hash_map::DefaultHasher;
3536

3637
#[cfg(test)] #[macro_use] mod bench;
3738

@@ -47,7 +48,7 @@ mod vec_deque;
4748
mod vec;
4849

4950
fn hash<T: Hash>(t: &T) -> u64 {
50-
let mut s = SipHasher::new();
51+
let mut s = DefaultHasher::new();
5152
t.hash(&mut s);
5253
s.finish()
5354
}

src/libcore/cell.rs

+21-25
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175

176176
use cmp::Ordering;
177177
use fmt::{self, Debug, Display};
178-
use marker::{PhantomData, Unsize};
178+
use marker::Unsize;
179179
use ops::{Deref, DerefMut, CoerceUnsized};
180180

181181
/// A mutable memory location that admits only `Copy` data.
@@ -403,40 +403,40 @@ pub enum BorrowState {
403403
}
404404

405405
/// An error returned by [`RefCell::try_borrow`](struct.RefCell.html#method.try_borrow).
406-
#[unstable(feature = "try_borrow", issue = "35070")]
407-
pub struct BorrowError<'a, T: 'a + ?Sized> {
408-
marker: PhantomData<&'a RefCell<T>>,
406+
#[stable(feature = "try_borrow", since = "1.13.0")]
407+
pub struct BorrowError {
408+
_private: (),
409409
}
410410

411-
#[unstable(feature = "try_borrow", issue = "35070")]
412-
impl<'a, T: ?Sized> Debug for BorrowError<'a, T> {
411+
#[stable(feature = "try_borrow", since = "1.13.0")]
412+
impl Debug for BorrowError {
413413
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
414414
f.debug_struct("BorrowError").finish()
415415
}
416416
}
417417

418-
#[unstable(feature = "try_borrow", issue = "35070")]
419-
impl<'a, T: ?Sized> Display for BorrowError<'a, T> {
418+
#[stable(feature = "try_borrow", since = "1.13.0")]
419+
impl Display for BorrowError {
420420
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
421421
Display::fmt("already mutably borrowed", f)
422422
}
423423
}
424424

425425
/// An error returned by [`RefCell::try_borrow_mut`](struct.RefCell.html#method.try_borrow_mut).
426-
#[unstable(feature = "try_borrow", issue = "35070")]
427-
pub struct BorrowMutError<'a, T: 'a + ?Sized> {
428-
marker: PhantomData<&'a RefCell<T>>,
426+
#[stable(feature = "try_borrow", since = "1.13.0")]
427+
pub struct BorrowMutError {
428+
_private: (),
429429
}
430430

431-
#[unstable(feature = "try_borrow", issue = "35070")]
432-
impl<'a, T: ?Sized> Debug for BorrowMutError<'a, T> {
431+
#[stable(feature = "try_borrow", since = "1.13.0")]
432+
impl Debug for BorrowMutError {
433433
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
434434
f.debug_struct("BorrowMutError").finish()
435435
}
436436
}
437437

438-
#[unstable(feature = "try_borrow", issue = "35070")]
439-
impl<'a, T: ?Sized> Display for BorrowMutError<'a, T> {
438+
#[stable(feature = "try_borrow", since = "1.13.0")]
439+
impl Display for BorrowMutError {
440440
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
441441
Display::fmt("already borrowed", f)
442442
}
@@ -573,8 +573,6 @@ impl<T: ?Sized> RefCell<T> {
573573
/// # Examples
574574
///
575575
/// ```
576-
/// #![feature(try_borrow)]
577-
///
578576
/// use std::cell::RefCell;
579577
///
580578
/// let c = RefCell::new(5);
@@ -589,15 +587,15 @@ impl<T: ?Sized> RefCell<T> {
589587
/// assert!(c.try_borrow().is_ok());
590588
/// }
591589
/// ```
592-
#[unstable(feature = "try_borrow", issue = "35070")]
590+
#[stable(feature = "try_borrow", since = "1.13.0")]
593591
#[inline]
594-
pub fn try_borrow(&self) -> Result<Ref<T>, BorrowError<T>> {
592+
pub fn try_borrow(&self) -> Result<Ref<T>, BorrowError> {
595593
match BorrowRef::new(&self.borrow) {
596594
Some(b) => Ok(Ref {
597595
value: unsafe { &*self.value.get() },
598596
borrow: b,
599597
}),
600-
None => Err(BorrowError { marker: PhantomData }),
598+
None => Err(BorrowError { _private: () }),
601599
}
602600
}
603601

@@ -654,8 +652,6 @@ impl<T: ?Sized> RefCell<T> {
654652
/// # Examples
655653
///
656654
/// ```
657-
/// #![feature(try_borrow)]
658-
///
659655
/// use std::cell::RefCell;
660656
///
661657
/// let c = RefCell::new(5);
@@ -667,15 +663,15 @@ impl<T: ?Sized> RefCell<T> {
667663
///
668664
/// assert!(c.try_borrow_mut().is_ok());
669665
/// ```
670-
#[unstable(feature = "try_borrow", issue = "35070")]
666+
#[stable(feature = "try_borrow", since = "1.13.0")]
671667
#[inline]
672-
pub fn try_borrow_mut(&self) -> Result<RefMut<T>, BorrowMutError<T>> {
668+
pub fn try_borrow_mut(&self) -> Result<RefMut<T>, BorrowMutError> {
673669
match BorrowRefMut::new(&self.borrow) {
674670
Some(b) => Ok(RefMut {
675671
value: unsafe { &mut *self.value.get() },
676672
borrow: b,
677673
}),
678-
None => Err(BorrowMutError { marker: PhantomData }),
674+
None => Err(BorrowMutError { _private: () }),
679675
}
680676
}
681677

src/libcore/hash/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ use marker;
7676
use mem;
7777

7878
#[stable(feature = "rust1", since = "1.0.0")]
79+
#[allow(deprecated)]
7980
pub use self::sip::SipHasher;
8081

8182
#[unstable(feature = "sip_hash_13", issue = "29754")]
83+
#[allow(deprecated)]
8284
pub use self::sip::{SipHasher13, SipHasher24};
8385

8486
mod sip;

src/libcore/hash/sip.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010

1111
//! An implementation of SipHash.
1212
13+
#![allow(deprecated)]
14+
1315
use marker::PhantomData;
1416
use ptr;
1517

1618
/// An implementation of SipHash 1-3.
1719
///
1820
/// See: https://131002.net/siphash/
1921
#[unstable(feature = "sip_hash_13", issue = "34767")]
22+
#[rustc_deprecated(since = "1.13.0", reason = "use `DefaultHasher` instead")]
2023
#[derive(Debug, Clone, Default)]
2124
pub struct SipHasher13 {
2225
hasher: Hasher<Sip13Rounds>,
@@ -26,6 +29,7 @@ pub struct SipHasher13 {
2629
///
2730
/// See: https://131002.net/siphash/
2831
#[unstable(feature = "sip_hash_13", issue = "34767")]
32+
#[rustc_deprecated(since = "1.13.0", reason = "use `DefaultHasher` instead")]
2933
#[derive(Debug, Clone, Default)]
3034
pub struct SipHasher24 {
3135
hasher: Hasher<Sip24Rounds>,
@@ -47,6 +51,7 @@ pub struct SipHasher24 {
4751
/// it is not intended for cryptographic purposes. As such, all
4852
/// cryptographic uses of this implementation are _strongly discouraged_.
4953
#[stable(feature = "rust1", since = "1.0.0")]
54+
#[rustc_deprecated(since = "1.13.0", reason = "use `DefaultHasher` instead")]
5055
#[derive(Debug, Clone, Default)]
5156
pub struct SipHasher(SipHasher24);
5257

@@ -136,30 +141,33 @@ impl SipHasher {
136141
/// Creates a new `SipHasher` with the two initial keys set to 0.
137142
#[inline]
138143
#[stable(feature = "rust1", since = "1.0.0")]
144+
#[rustc_deprecated(since = "1.13.0", reason = "use `DefaultHasher` instead")]
139145
pub fn new() -> SipHasher {
140146
SipHasher::new_with_keys(0, 0)
141147
}
142148

143149
/// Creates a `SipHasher` that is keyed off the provided keys.
144150
#[inline]
145151
#[stable(feature = "rust1", since = "1.0.0")]
152+
#[rustc_deprecated(since = "1.13.0", reason = "use `DefaultHasher` instead")]
146153
pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher {
147154
SipHasher(SipHasher24::new_with_keys(key0, key1))
148155
}
149156
}
150157

151-
152158
impl SipHasher13 {
153159
/// Creates a new `SipHasher13` with the two initial keys set to 0.
154160
#[inline]
155161
#[unstable(feature = "sip_hash_13", issue = "34767")]
162+
#[rustc_deprecated(since = "1.13.0", reason = "use `DefaultHasher` instead")]
156163
pub fn new() -> SipHasher13 {
157164
SipHasher13::new_with_keys(0, 0)
158165
}
159166

160167
/// Creates a `SipHasher13` that is keyed off the provided keys.
161168
#[inline]
162169
#[unstable(feature = "sip_hash_13", issue = "34767")]
170+
#[rustc_deprecated(since = "1.13.0", reason = "use `DefaultHasher` instead")]
163171
pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher13 {
164172
SipHasher13 {
165173
hasher: Hasher::new_with_keys(key0, key1)
@@ -171,13 +179,15 @@ impl SipHasher24 {
171179
/// Creates a new `SipHasher24` with the two initial keys set to 0.
172180
#[inline]
173181
#[unstable(feature = "sip_hash_13", issue = "34767")]
182+
#[rustc_deprecated(since = "1.13.0", reason = "use `DefaultHasher` instead")]
174183
pub fn new() -> SipHasher24 {
175184
SipHasher24::new_with_keys(0, 0)
176185
}
177186

178187
/// Creates a `SipHasher24` that is keyed off the provided keys.
179188
#[inline]
180189
#[unstable(feature = "sip_hash_13", issue = "34767")]
190+
#[rustc_deprecated(since = "1.13.0", reason = "use `DefaultHasher` instead")]
181191
pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher24 {
182192
SipHasher24 {
183193
hasher: Hasher::new_with_keys(key0, key1)

src/libcore/num/mod.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -613,14 +613,12 @@ macro_rules! int_impl {
613613
/// Basic usage:
614614
///
615615
/// ```
616-
/// # #![feature(no_panic_abs)]
617-
///
618616
/// use std::i32;
619617
///
620618
/// assert_eq!((-5i32).checked_abs(), Some(5));
621619
/// assert_eq!(i32::MIN.checked_abs(), None);
622620
/// ```
623-
#[unstable(feature = "no_panic_abs", issue = "35057")]
621+
#[stable(feature = "no_panic_abs", since = "1.13.0")]
624622
#[inline]
625623
pub fn checked_abs(self) -> Option<Self> {
626624
if self.is_negative() {
@@ -895,14 +893,12 @@ macro_rules! int_impl {
895893
/// Basic usage:
896894
///
897895
/// ```
898-
/// # #![feature(no_panic_abs)]
899-
///
900896
/// assert_eq!(100i8.wrapping_abs(), 100);
901897
/// assert_eq!((-100i8).wrapping_abs(), 100);
902898
/// assert_eq!((-128i8).wrapping_abs(), -128);
903899
/// assert_eq!((-128i8).wrapping_abs() as u8, 128);
904900
/// ```
905-
#[unstable(feature = "no_panic_abs", issue = "35057")]
901+
#[stable(feature = "no_panic_abs", since = "1.13.0")]
906902
#[inline(always)]
907903
pub fn wrapping_abs(self) -> Self {
908904
if self.is_negative() {
@@ -1133,13 +1129,11 @@ macro_rules! int_impl {
11331129
/// Basic usage:
11341130
///
11351131
/// ```
1136-
/// # #![feature(no_panic_abs)]
1137-
///
11381132
/// assert_eq!(10i8.overflowing_abs(), (10,false));
11391133
/// assert_eq!((-10i8).overflowing_abs(), (10,false));
11401134
/// assert_eq!((-128i8).overflowing_abs(), (-128,true));
11411135
/// ```
1142-
#[unstable(feature = "no_panic_abs", issue = "35057")]
1136+
#[stable(feature = "no_panic_abs", since = "1.13.0")]
11431137
#[inline]
11441138
pub fn overflowing_abs(self) -> (Self, bool) {
11451139
if self.is_negative() {

src/libcoretest/hash/sip.rs

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
10+
11+
#![allow(deprecated)]
12+
1013
use test::{Bencher, black_box};
1114

1215
use core::hash::{Hash, Hasher};

src/librustc/hir/map/definitions.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
use hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE};
1212
use rustc_data_structures::fnv::FnvHashMap;
1313
use std::fmt::Write;
14-
use std::hash::{Hash, Hasher, SipHasher};
14+
use std::hash::{Hash, Hasher};
15+
use std::collections::hash_map::DefaultHasher;
1516
use syntax::ast;
1617
use syntax::parse::token::{self, InternedString};
1718
use ty::TyCtxt;
@@ -130,7 +131,7 @@ impl DefPath {
130131
}
131132

132133
pub fn deterministic_hash(&self, tcx: TyCtxt) -> u64 {
133-
let mut state = SipHasher::new();
134+
let mut state = DefaultHasher::new();
134135
self.deterministic_hash_to(tcx, &mut state);
135136
state.finish()
136137
}

0 commit comments

Comments
 (0)