Skip to content

Commit fcd76b4

Browse files
authored
Rollup merge of rust-lang#53782 - rask:task/arc-docs-adjustment, r=cramertj
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
2 parents 8d161a6 + bf7e324 commit fcd76b4

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,10 @@ 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 `Arc` instance, which points to the same value on the heap as the
53+
/// source `Arc`, while increasing a reference count. When the last `Arc`
54+
/// pointer to a given value is destroyed, the pointed-to value is also
55+
/// destroyed.
5556
///
5657
/// Shared references in Rust disallow mutation by default, and `Arc` is no
5758
/// exception: you cannot generally obtain a mutable reference to something
@@ -107,7 +108,7 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
107108
/// // The two syntaxes below are equivalent.
108109
/// let a = foo.clone();
109110
/// let b = Arc::clone(&foo);
110-
/// // a and b both point to the same memory location as foo.
111+
/// // a, b, and foo are all Arcs that point to the same memory location
111112
/// ```
112113
///
113114
/// The [`Arc::clone(&from)`] syntax is the most idiomatic because it conveys more explicitly

0 commit comments

Comments
 (0)