Skip to content

Commit 4a07e72

Browse files
In std:rc, clarify the lack of mutability inside an Rc
Also, point to the example in Cell's docs for how to do it.
1 parent 1283c02 commit 4a07e72

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/liballoc/rc.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
//! pointer to the same value in the heap. When the last [`Rc`] pointer to a
1818
//! given value is destroyed, the pointed-to value is also destroyed.
1919
//!
20-
//! Shared references in Rust disallow mutation by default, and `Rc` is no
21-
//! exception. If you need to mutate through an [`Rc`], use [`Cell`] or
22-
//! [`RefCell`].
20+
//! Shared references in Rust disallow mutation by default, and [`Rc`]
21+
//! is no exception: you cannot obtain a mutable reference to
22+
//! something inside an [`Rc`]. If you need mutability, put a [`Cell`]
23+
//! or [`RefCell`] inside the [`Rc`]; see [an example of mutability
24+
//! inside an Rc][mutability].
2325
//!
2426
//! [`Rc`] uses non-atomic reference counting. This means that overhead is very
2527
//! low, but an [`Rc`] cannot be sent between threads, and consequently [`Rc`]
@@ -214,6 +216,7 @@
214216
//! [upgrade]: struct.Weak.html#method.upgrade
215217
//! [`None`]: ../../std/option/enum.Option.html#variant.None
216218
//! [assoc]: ../../book/method-syntax.html#associated-functions
219+
//! [mutability]: ../../std/cell/index.html#introducing-mutability-inside-of-something-immutable
217220
218221
#![stable(feature = "rust1", since = "1.0.0")]
219222

0 commit comments

Comments
 (0)