Skip to content

Commit 47efa49

Browse files
authored
Rollup merge of rust-lang#61135 - czipperz:rc-make_mut-weak-doc, r=Mark-Simulacrum
Fix documentation of `Rc::make_mut` regarding `rc::Weak`. Closes rust-lang#60961
2 parents e22b7a3 + b34b714 commit 47efa49

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

src/liballoc/rc.rs

+27-7
Original file line numberDiff line numberDiff line change
@@ -580,15 +580,18 @@ impl<T: ?Sized> Rc<T> {
580580
impl<T: Clone> Rc<T> {
581581
/// Makes a mutable reference into the given `Rc`.
582582
///
583-
/// If there are other `Rc` or [`Weak`][weak] pointers to the same value,
584-
/// then `make_mut` will invoke [`clone`][clone] on the inner value to
585-
/// ensure unique ownership. This is also referred to as clone-on-write.
583+
/// If there are other `Rc` pointers to the same value, then `make_mut` will
584+
/// [`clone`] the inner value to ensure unique ownership. This is also
585+
/// referred to as clone-on-write.
586586
///
587-
/// See also [`get_mut`][get_mut], which will fail rather than cloning.
587+
/// If there are no other `Rc` pointers to this value, then [`Weak`]
588+
/// pointers to this value will be dissassociated.
588589
///
589-
/// [weak]: struct.Weak.html
590-
/// [clone]: ../../std/clone/trait.Clone.html#tymethod.clone
591-
/// [get_mut]: struct.Rc.html#method.get_mut
590+
/// See also [`get_mut`], which will fail rather than cloning.
591+
///
592+
/// [`Weak`]: struct.Weak.html
593+
/// [`clone`]: ../../std/clone/trait.Clone.html#tymethod.clone
594+
/// [`get_mut`]: struct.Rc.html#method.get_mut
592595
///
593596
/// # Examples
594597
///
@@ -607,6 +610,23 @@ impl<T: Clone> Rc<T> {
607610
/// assert_eq!(*data, 8);
608611
/// assert_eq!(*other_data, 12);
609612
/// ```
613+
///
614+
/// [`Weak`] pointers will be dissassociated:
615+
///
616+
/// ```
617+
/// use std::rc::Rc;
618+
///
619+
/// let mut data = Rc::new(75);
620+
/// let weak = Rc::downgrade(&data);
621+
///
622+
/// assert!(75 == *data);
623+
/// assert!(75 == *weak.upgrade().unwrap());
624+
///
625+
/// *Rc::make_mut(&mut data) += 1;
626+
///
627+
/// assert!(76 == *data);
628+
/// assert!(weak.upgrade().is_none());
629+
/// ```
610630
#[inline]
611631
#[stable(feature = "rc_unique", since = "1.4.0")]
612632
pub fn make_mut(this: &mut Self) -> &mut T {

0 commit comments

Comments
 (0)