Skip to content

Commit

Permalink
Rollup merge of rust-lang#61135 - czipperz:rc-make_mut-weak-doc, r=Ma…
Browse files Browse the repository at this point in the history
…rk-Simulacrum

Fix documentation of `Rc::make_mut` regarding `rc::Weak`.

Closes rust-lang#60961
  • Loading branch information
Centril authored Jun 4, 2019
2 parents e22b7a3 + b34b714 commit 47efa49
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,15 +580,18 @@ impl<T: ?Sized> Rc<T> {
impl<T: Clone> Rc<T> {
/// Makes a mutable reference into the given `Rc`.
///
/// If there are other `Rc` or [`Weak`][weak] pointers to the same value,
/// then `make_mut` will invoke [`clone`][clone] on the inner value to
/// ensure unique ownership. This is also referred to as clone-on-write.
/// If there are other `Rc` pointers to the same value, then `make_mut` will
/// [`clone`] the inner value to ensure unique ownership. This is also
/// referred to as clone-on-write.
///
/// See also [`get_mut`][get_mut], which will fail rather than cloning.
/// If there are no other `Rc` pointers to this value, then [`Weak`]
/// pointers to this value will be dissassociated.
///
/// [weak]: struct.Weak.html
/// [clone]: ../../std/clone/trait.Clone.html#tymethod.clone
/// [get_mut]: struct.Rc.html#method.get_mut
/// See also [`get_mut`], which will fail rather than cloning.
///
/// [`Weak`]: struct.Weak.html
/// [`clone`]: ../../std/clone/trait.Clone.html#tymethod.clone
/// [`get_mut`]: struct.Rc.html#method.get_mut
///
/// # Examples
///
Expand All @@ -607,6 +610,23 @@ impl<T: Clone> Rc<T> {
/// assert_eq!(*data, 8);
/// assert_eq!(*other_data, 12);
/// ```
///
/// [`Weak`] pointers will be dissassociated:
///
/// ```
/// use std::rc::Rc;
///
/// let mut data = Rc::new(75);
/// let weak = Rc::downgrade(&data);
///
/// assert!(75 == *data);
/// assert!(75 == *weak.upgrade().unwrap());
///
/// *Rc::make_mut(&mut data) += 1;
///
/// assert!(76 == *data);
/// assert!(weak.upgrade().is_none());
/// ```
#[inline]
#[stable(feature = "rc_unique", since = "1.4.0")]
pub fn make_mut(this: &mut Self) -> &mut T {
Expand Down

0 comments on commit 47efa49

Please sign in to comment.