Skip to content

Commit f60cb17

Browse files
Rollup merge of rust-lang#35418 - birkenfeld:patch-1, r=aturon
Doc: explain why Box/Rc/Arc methods do not take self This can be confusing for newcomers, especially due to the argument name `this` that is used for Rc and Arc.
2 parents addb753 + a068fc7 commit f60cb17

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/liballoc/arc.rs

+6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
7171
/// does not use atomics, making it both thread-unsafe as well as significantly
7272
/// faster when updating the reference count.
7373
///
74+
/// Note: the inherent methods defined on `Arc<T>` are all associated functions,
75+
/// which means that you have to call them as e.g. `Arc::get_mut(&value)`
76+
/// instead of `value.get_mut()`. This is so that there are no conflicts with
77+
/// methods on the inner type `T`, which are what you want to call in the
78+
/// majority of cases.
79+
///
7480
/// # Examples
7581
///
7682
/// In this example, a large vector of data will be shared by several threads. First we

src/liballoc/boxed.rs

+4
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ impl<T: ?Sized> Box<T> {
271271
/// proper way to do so is to convert the raw pointer back into a
272272
/// `Box` with the `Box::from_raw` function.
273273
///
274+
/// Note: this is an associated function, which means that you have
275+
/// to call it as `Box::into_raw(b)` instead of `b.into_raw()`. This
276+
/// is so that there is no conflict with a method on the inner type.
277+
///
274278
/// # Examples
275279
///
276280
/// ```

src/liballoc/rc.rs

+6
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ struct RcBox<T: ?Sized> {
182182
/// A reference-counted pointer type over an immutable value.
183183
///
184184
/// See the [module level documentation](./index.html) for more details.
185+
///
186+
/// Note: the inherent methods defined on `Rc<T>` are all associated functions,
187+
/// which means that you have to call them as e.g. `Rc::get_mut(&value)` instead
188+
/// of `value.get_mut()`. This is so that there are no conflicts with methods
189+
/// on the inner type `T`, which are what you want to call in the majority of
190+
/// cases.
185191
#[cfg_attr(stage0, unsafe_no_drop_flag)]
186192
#[stable(feature = "rust1", since = "1.0.0")]
187193
pub struct Rc<T: ?Sized> {

0 commit comments

Comments
 (0)