Skip to content

Commit e445648

Browse files
authored
Rollup merge of #109504 - steffahn:stabilize_a_rc_into_inner, r=joshtriplett
Stabilize `arc_into_inner` and `rc_into_inner`. Stabilize the `arc_into_inner` and `rc_into_inner` library features and thus close #106894. The changes in this PR also resolve the FIXMEs for adjusting the documentation upon stabilization, and I’ve additionally included some very minor documentation improvements. ```@rustbot``` label +T-libs-api -T-libs
2 parents 7afed92 + e8be3d2 commit e445648

File tree

2 files changed

+6
-23
lines changed

2 files changed

+6
-23
lines changed

library/alloc/src/rc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -692,10 +692,10 @@ impl<T> Rc<T> {
692692
/// it is guaranteed that exactly one of the calls returns the inner value.
693693
/// This means in particular that the inner value is not dropped.
694694
///
695-
/// This is equivalent to `Rc::try_unwrap(...).ok()`. (Note that these are not equivalent for
696-
/// `Arc`, due to race conditions that do not apply to `Rc`.)
695+
/// This is equivalent to `Rc::try_unwrap(this).ok()`. (Note that these are not equivalent for
696+
/// [`Arc`](crate::sync::Arc), due to race conditions that do not apply to `Rc`.)
697697
#[inline]
698-
#[unstable(feature = "rc_into_inner", issue = "106894")]
698+
#[stable(feature = "rc_into_inner", since = "CURRENT_RUSTC_VERSION")]
699699
pub fn into_inner(this: Self) -> Option<T> {
700700
Rc::try_unwrap(this).ok()
701701
}

library/alloc/src/sync.rs

+3-20
Original file line numberDiff line numberDiff line change
@@ -662,20 +662,17 @@ impl<T> Arc<T> {
662662
///
663663
/// This will succeed even if there are outstanding weak references.
664664
///
665-
// FIXME: when `Arc::into_inner` is stabilized, add this paragraph:
666-
/*
667665
/// It is strongly recommended to use [`Arc::into_inner`] instead if you don't
668666
/// want to keep the `Arc` in the [`Err`] case.
669667
/// Immediately dropping the [`Err`] payload, like in the expression
670668
/// `Arc::try_unwrap(this).ok()`, can still cause the strong count to
671669
/// drop to zero and the inner value of the `Arc` to be dropped:
672-
/// For instance if two threads execute this expression in parallel, then
670+
/// For instance if two threads each execute this expression in parallel, then
673671
/// there is a race condition. The threads could first both check whether they
674672
/// have the last clone of their `Arc` via `Arc::try_unwrap`, and then
675673
/// both drop their `Arc` in the call to [`ok`][`Result::ok`],
676674
/// taking the strong count from two down to zero.
677675
///
678-
*/
679676
/// # Examples
680677
///
681678
/// ```
@@ -719,20 +716,13 @@ impl<T> Arc<T> {
719716
/// This means in particular that the inner value is not dropped.
720717
///
721718
/// The similar expression `Arc::try_unwrap(this).ok()` does not
722-
/// offer such a guarantee. See the last example below.
723-
//
724-
// FIXME: when `Arc::into_inner` is stabilized, add this to end
725-
// of the previous sentence:
726-
/*
719+
/// offer such a guarantee. See the last example below
727720
/// and the documentation of [`Arc::try_unwrap`].
728-
*/
729721
///
730722
/// # Examples
731723
///
732724
/// Minimal example demonstrating the guarantee that `Arc::into_inner` gives.
733725
/// ```
734-
/// #![feature(arc_into_inner)]
735-
///
736726
/// use std::sync::Arc;
737727
///
738728
/// let x = Arc::new(3);
@@ -756,8 +746,6 @@ impl<T> Arc<T> {
756746
///
757747
/// A more practical example demonstrating the need for `Arc::into_inner`:
758748
/// ```
759-
/// #![feature(arc_into_inner)]
760-
///
761749
/// use std::sync::Arc;
762750
///
763751
/// // Definition of a simple singly linked list using `Arc`:
@@ -807,13 +795,8 @@ impl<T> Arc<T> {
807795
/// x_thread.join().unwrap();
808796
/// y_thread.join().unwrap();
809797
/// ```
810-
811-
// FIXME: when `Arc::into_inner` is stabilized, adjust above documentation
812-
// and the documentation of `Arc::try_unwrap` according to the `FIXME`s. Also
813-
// open an issue on rust-lang/rust-clippy, asking for a lint against
814-
// `Arc::try_unwrap(...).ok()`.
815798
#[inline]
816-
#[unstable(feature = "arc_into_inner", issue = "106894")]
799+
#[stable(feature = "arc_into_inner", since = "CURRENT_RUSTC_VERSION")]
817800
pub fn into_inner(this: Self) -> Option<T> {
818801
// Make sure that the ordinary `Drop` implementation isn’t called as well
819802
let mut this = mem::ManuallyDrop::new(this);

0 commit comments

Comments
 (0)