Skip to content

Commit 4528b37

Browse files
authored
Rollup merge of rust-lang#120266 - steffahn:a_rc_into_inner_docs, r=Mark-Simulacrum
Improve documentation for [A]Rc::into_inner General improvements, and also aims to better encourage the reader to actually check out Arc::try_unwrap. This addresses concerns from rust-lang#106894 (comment). Rendered: ![Screenshot_20240123_114436](https://github.com/rust-lang/rust/assets/3986214/68896d62-13e0-4f3a-8073-91d8e77c5554) ![Screenshot_20240123_114455](https://github.com/rust-lang/rust/assets/3986214/dc58e4bd-dd7f-40b1-bc50-fd6200dde593)
2 parents 0138151 + ab938b9 commit 4528b37

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

library/alloc/src/rc.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -939,8 +939,11 @@ impl<T, A: Allocator> Rc<T, A> {
939939
/// it is guaranteed that exactly one of the calls returns the inner value.
940940
/// This means in particular that the inner value is not dropped.
941941
///
942-
/// This is equivalent to `Rc::try_unwrap(this).ok()`. (Note that these are not equivalent for
943-
/// [`Arc`](crate::sync::Arc), due to race conditions that do not apply to `Rc`.)
942+
/// [`Rc::try_unwrap`] is conceptually similar to `Rc::into_inner`.
943+
/// And while they are meant for different use-cases, `Rc::into_inner(this)`
944+
/// is in fact equivalent to <code>[Rc::try_unwrap]\(this).[ok][Result::ok]()</code>.
945+
/// (Note that the same kind of equivalence does **not** hold true for
946+
/// [`Arc`](crate::sync::Arc), due to race conditions that do not apply to `Rc`!)
944947
#[inline]
945948
#[stable(feature = "rc_into_inner", since = "1.70.0")]
946949
pub fn into_inner(this: Self) -> Option<T> {

library/alloc/src/sync.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -983,9 +983,13 @@ impl<T, A: Allocator> Arc<T, A> {
983983
/// it is guaranteed that exactly one of the calls returns the inner value.
984984
/// This means in particular that the inner value is not dropped.
985985
///
986-
/// The similar expression `Arc::try_unwrap(this).ok()` does not
987-
/// offer such a guarantee. See the last example below
988-
/// and the documentation of [`Arc::try_unwrap`].
986+
/// [`Arc::try_unwrap`] is conceptually similar to `Arc::into_inner`, but it
987+
/// is meant for different use-cases. If used as a direct replacement
988+
/// for `Arc::into_inner` anyway, such as with the expression
989+
/// <code>[Arc::try_unwrap]\(this).[ok][Result::ok]()</code>, then it does
990+
/// **not** give the same guarantee as described in the previous paragraph.
991+
/// For more information, see the examples below and read the documentation
992+
/// of [`Arc::try_unwrap`].
989993
///
990994
/// # Examples
991995
///

0 commit comments

Comments
 (0)