Skip to content

Make Arc cloning mechanics clearer in module docs #53782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 1, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/liballoc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
///
/// The type `Arc<T>` provides shared ownership of a value of type `T`,
/// allocated in the heap. Invoking [`clone`][clone] on `Arc` produces
/// a new pointer to the same value in the heap. When the last `Arc`
/// pointer to a given value is destroyed, the pointed-to value is
/// also destroyed.
/// a new pointer to the same `Arc` reference value in the heap. When the last
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more accurate to say "produces a new Arc pointing to the same value in the heap". The source might make it clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh it works like that! So the internal reference is cloned. Been hearing varying descriptions on how it works. I can change it to reflect that soon. Thanks for clarifying.

/// `Arc` pointer to a given value is destroyed, the pointed-to value is also
/// destroyed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds better now!

///
/// Shared references in Rust disallow mutation by default, and `Arc` is no
/// exception: you cannot generally obtain a mutable reference to something
Expand Down Expand Up @@ -107,7 +107,8 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
/// // The two syntaxes below are equivalent.
/// let a = foo.clone();
/// let b = Arc::clone(&foo);
/// // a and b both point to the same memory location as foo.
/// // a and b both point to the same memory location where foo resides
/// // (not where the value wrapped by foo resides).
Copy link
Contributor

@durka durka Aug 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact a, b, and foo are all separate Arcs pointing to the memory location (where the Vec resides (okay actually a couple bytes away from it, to make room for the reference counts)). So I don't think this change is necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per your other comment, I agree, will remove this.

/// ```
///
/// The [`Arc::clone(&from)`] syntax is the most idiomatic because it conveys more explicitly
Expand Down