Skip to content

Commit 1e28132

Browse files
committed
Rename unwrap_or_drop to into_inner.
1 parent 7d43bcb commit 1e28132

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

library/alloc/src/sync.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,9 @@ impl<T> Arc<T> {
485485
///
486486
/// This will succeed even if there are outstanding weak references.
487487
///
488-
// FIXME: when `Arc::unwrap_or_drop` is stabilized, add this paragraph:
488+
// FIXME: when `Arc::into_inner` is stabilized, add this paragraph:
489489
/*
490-
/// It is strongly recommended to use [`Arc::unwrap_or_drop`] instead if you don't
490+
/// It is strongly recommended to use [`Arc::into_inner`] instead if you don't
491491
/// want to keep the `Arc` in the [`Err`] case.
492492
/// Immediately dropping the [`Err`] payload, like in the expression
493493
/// `Arc::try_unwrap(this).ok()`, can still cause the strong count to
@@ -537,7 +537,7 @@ impl<T> Arc<T> {
537537
///
538538
/// This will succeed even if there are outstanding weak references.
539539
///
540-
/// If `unwrap_or_drop` is called on every clone of this `Arc`,
540+
/// If `into_inner` is called on every clone of this `Arc`,
541541
/// it is guaranteed that exactly one of the calls returns the inner value.
542542
/// This means in particular that the inner value is not dropped.
543543
///
@@ -547,18 +547,18 @@ impl<T> Arc<T> {
547547
///
548548
/// # Examples
549549
///
550-
/// Minimal example demonstrating the guarantee that `unwrap_or_drop` gives.
550+
/// Minimal example demonstrating the guarantee that `into_inner` gives.
551551
/// ```
552-
/// #![feature(unwrap_or_drop)]
552+
/// #![feature(arc_into_inner)]
553553
///
554554
/// use std::sync::Arc;
555555
///
556556
/// let x = Arc::new(3);
557557
/// let y = Arc::clone(&x);
558558
///
559-
/// // Two threads calling `unwrap_or_drop` on both clones of an `Arc`:
560-
/// let x_unwrap_thread = std::thread::spawn(|| Arc::unwrap_or_drop(x));
561-
/// let y_unwrap_thread = std::thread::spawn(|| Arc::unwrap_or_drop(y));
559+
/// // Two threads calling `into_inner` on both clones of an `Arc`:
560+
/// let x_unwrap_thread = std::thread::spawn(|| Arc::into_inner(x));
561+
/// let y_unwrap_thread = std::thread::spawn(|| Arc::into_inner(y));
562562
///
563563
/// let x_unwrapped_value = x_unwrap_thread.join().unwrap();
564564
/// let y_unwrapped_value = y_unwrap_thread.join().unwrap();
@@ -572,9 +572,9 @@ impl<T> Arc<T> {
572572
/// // `Arc::try_unwrap(x).ok()` and `Arc::try_unwrap(y).ok()` instead.
573573
/// ```
574574
///
575-
/// A more practical example demonstrating the need for `unwrap_or_drop`:
575+
/// A more practical example demonstrating the need for `into_inner`:
576576
/// ```
577-
/// #![feature(unwrap_or_drop)]
577+
/// #![feature(arc_into_inner)]
578578
///
579579
/// use std::sync::Arc;
580580
///
@@ -590,7 +590,7 @@ impl<T> Arc<T> {
590590
/// fn drop(&mut self) {
591591
/// let mut x = self.0.take();
592592
/// while let Some(arc) = x.take() {
593-
/// Arc::unwrap_or_drop(arc).map(|node| x = node.1);
593+
/// Arc::into_inner(arc).map(|node| x = node.1);
594594
/// }
595595
/// }
596596
/// }
@@ -608,7 +608,7 @@ impl<T> Arc<T> {
608608
///
609609
/// // The following code could still cause a stack overflow
610610
/// // despite the manual `Drop` impl if that `Drop` impl used
611-
/// // `Arc::try_unwrap(arc).ok()` instead of `Arc::unwrap_or_drop(arc)`.
611+
/// // `Arc::try_unwrap(arc).ok()` instead of `Arc::into_inner(arc)`.
612612
/// {
613613
/// // Create a long list and clone it
614614
/// let mut x = LinkedList::new();
@@ -625,11 +625,11 @@ impl<T> Arc<T> {
625625
/// }
626626
/// ```
627627
628-
// FIXME: when `Arc::unwrap_or_drop` is stabilized, adjust the documentation of
628+
// FIXME: when `Arc::into_inner` is stabilized, adjust the documentation of
629629
// `Arc::try_unwrap` according to the `FIXME` presented there.
630630
#[inline]
631-
#[unstable(feature = "unwrap_or_drop", issue = "none")] // FIXME: add issue
632-
pub fn unwrap_or_drop(this: Self) -> Option<T> {
631+
#[unstable(feature = "arc_into_inner", issue = "none")] // FIXME: create and add issue
632+
pub fn into_inner(this: Self) -> Option<T> {
633633
// Make sure that the ordinary `Drop` implementation isn’t called as well
634634
let mut this = mem::ManuallyDrop::new(this);
635635

library/alloc/src/sync/tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ fn try_unwrap() {
102102
}
103103

104104
#[test]
105-
fn unwrap_or_drop() {
105+
fn into_inner() {
106106
for _ in 0..100
107107
// ^ Increase chances of hitting potential race conditions
108108
{
109109
let x = Arc::new(3);
110110
let y = Arc::clone(&x);
111-
let r_thread = std::thread::spawn(|| Arc::unwrap_or_drop(x));
112-
let s_thread = std::thread::spawn(|| Arc::unwrap_or_drop(y));
111+
let r_thread = std::thread::spawn(|| Arc::into_inner(x));
112+
let s_thread = std::thread::spawn(|| Arc::into_inner(y));
113113
let r = r_thread.join().expect("r_thread panicked");
114114
let s = s_thread.join().expect("s_thread panicked");
115115
assert!(
@@ -121,16 +121,16 @@ fn unwrap_or_drop() {
121121
}
122122

123123
let x = Arc::new(3);
124-
assert_eq!(Arc::unwrap_or_drop(x), Some(3));
124+
assert_eq!(Arc::into_inner(x), Some(3));
125125

126126
let x = Arc::new(4);
127127
let y = Arc::clone(&x);
128-
assert_eq!(Arc::unwrap_or_drop(x), None);
129-
assert_eq!(Arc::unwrap_or_drop(y), Some(4));
128+
assert_eq!(Arc::into_inner(x), None);
129+
assert_eq!(Arc::into_inner(y), Some(4));
130130

131131
let x = Arc::new(5);
132132
let _w = Arc::downgrade(&x);
133-
assert_eq!(Arc::unwrap_or_drop(x), Some(5));
133+
assert_eq!(Arc::into_inner(x), Some(5));
134134
}
135135

136136
#[test]

0 commit comments

Comments
 (0)