Skip to content

Commit 15241a4

Browse files
committed
Fix documentation of Rc::make_mut regarding rc::Weak.
1 parent fc45382 commit 15241a4

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

src/liballoc/rc.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -584,15 +584,18 @@ impl<T: ?Sized> Rc<T> {
584584
impl<T: Clone> Rc<T> {
585585
/// Makes a mutable reference into the given `Rc`.
586586
///
587-
/// If there are other `Rc` or [`Weak`][weak] pointers to the same value,
588-
/// then `make_mut` will invoke [`clone`][clone] on the inner value to
589-
/// ensure unique ownership. This is also referred to as clone-on-write.
587+
/// If there are other `Rc` pointers to the same value, then `make_mut` will
588+
/// [`clone`] the inner value to ensure unique ownership. This is also
589+
/// referred to as clone-on-write.
590590
///
591-
/// See also [`get_mut`][get_mut], which will fail rather than cloning.
591+
/// If there are not other `Rc` pointers to this value, then [`Weak`]
592+
/// pointers to this value will be dissassociated.
592593
///
593-
/// [weak]: struct.Weak.html
594-
/// [clone]: ../../std/clone/trait.Clone.html#tymethod.clone
595-
/// [get_mut]: struct.Rc.html#method.get_mut
594+
/// See also [`get_mut`], which will fail rather than cloning.
595+
///
596+
/// [`Weak`]: struct.Weak.html
597+
/// [`clone`]: ../../std/clone/trait.Clone.html#tymethod.clone
598+
/// [`get_mut`]: struct.Rc.html#method.get_mut
596599
///
597600
/// # Examples
598601
///
@@ -611,6 +614,23 @@ impl<T: Clone> Rc<T> {
611614
/// assert_eq!(*data, 8);
612615
/// assert_eq!(*other_data, 12);
613616
/// ```
617+
///
618+
/// [`Weak`] pointers will be dissassociated:
619+
///
620+
/// ```
621+
/// use std::rc::{Rc, Weak};
622+
///
623+
/// let mut data = Rc::new(75);
624+
/// let weak = Rc::downgrade(&data);
625+
///
626+
/// assert!(75 == *data);
627+
/// assert!(75 == *weak.upgrade().unwrap());
628+
///
629+
/// *Rc::make_mut(&mut data) += 1;
630+
///
631+
/// assert!(76 == *data);
632+
/// assert!(weak.upgrade().is_none());
633+
/// ```
614634
#[inline]
615635
#[stable(feature = "rc_unique", since = "1.4.0")]
616636
pub fn make_mut(this: &mut Self) -> &mut T {

0 commit comments

Comments
 (0)