Skip to content

Commit 5399616

Browse files
committed
Make Arc cloning mechanics clearer in module docs
Add some more wording to module documentation regarding how `Arc::clone()` works, as some users have assumed cloning Arc's to work via dereferencing to inner value as follows: use std::sync::Arc; let myarc = Arc::new(1); let myarcref = myarc.clone(); assert!(1 == myarcref); Instead of the actual mechanic of referencing the existing Arc value: use std::sync::Arg; let myarc = Arc::new(1); let myarcref = myarc.clone(); assert!(myarcref == &myarc); // not sure if assert could assert this in the real world
1 parent f4e981c commit 5399616

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/liballoc/sync.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
4949
///
5050
/// The type `Arc<T>` provides shared ownership of a value of type `T`,
5151
/// allocated in the heap. Invoking [`clone`][clone] on `Arc` produces
52-
/// a new pointer to the same value in the heap. When the last `Arc`
53-
/// pointer to a given value is destroyed, the pointed-to value is
54-
/// also destroyed.
52+
/// a new pointer to the same `Arc` reference value in the heap. When the last
53+
/// `Arc` pointer to a given value is destroyed, the pointed-to value is also
54+
/// destroyed.
5555
///
5656
/// Shared references in Rust disallow mutation by default, and `Arc` is no
5757
/// exception: you cannot generally obtain a mutable reference to something
@@ -107,7 +107,8 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
107107
/// // The two syntaxes below are equivalent.
108108
/// let a = foo.clone();
109109
/// let b = Arc::clone(&foo);
110-
/// // a and b both point to the same memory location as foo.
110+
/// // a and b both point to the same memory location where foo resides
111+
/// // (not where the value wrapped by foo resides).
111112
/// ```
112113
///
113114
/// The [`Arc::clone(&from)`] syntax is the most idiomatic because it conveys more explicitly

0 commit comments

Comments
 (0)