-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Document behavior of ptr::swap
with overlapping regions of memory.
#46483
Conversation
r? @BurntSushi (rust_highfive has picked a reviewer for you, use r? to override) |
src/libcore/ptr.rs
Outdated
/// otherwise equivalent. | ||
/// deinitializing either. The values pointed at by `x` and `y` may overlap, | ||
/// unlike `mem::swap` which is otherwise equivalent. If the values do overlap, | ||
/// then the overlapping region of memory will be derived from `x`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I understood the last sentence here until I looked at the example. Is there any way to write this more clearly? (The answer might be "no." I don't have any particularly good ideas.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another wording that comes to mind:
If the values do overlap, then the overlapping region of memory from
x
takes priority.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That does actually seem better to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adjusted in the latest force push
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to be honest, I didn't understand "takes priority" and I find the original wording better :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"will be used" is another possibility. It might also make sense to simply be like "see the example below" since this is definitely something an example clarifies greatly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
applied @gankro's suggestions in the latest force push
--- a/src/libcore/ptr.rs
+++ b/src/libcore/ptr.rs
@@ -91,9 +91,12 @@ pub const fn null<T>() -> *const T { 0 as *const T }
pub const fn null_mut<T>() -> *mut T { 0 as *mut T }
/// Swaps the values at two mutable locations of the same type, without
-/// deinitializing either. The values pointed at by `x` and `y` may overlap,
-/// unlike `mem::swap` which is otherwise equivalent. If the values do overlap,
-/// then the overlapping region of memory from `x` takes priority.
+/// deinitializing either.
+///
+/// The values pointed at by `x` and `y` may overlap, unlike `mem::swap` which
+/// is otherwise equivalent. If the values do overlap, then the overlapping
+/// region of memory from `x` will be used. This is demonstrated in the
+/// examples section below.
///
/// # Safety
///
a870185
to
9e5b9ab
Compare
sgtm |
I'm also a little unsure about how to phrase this, but if we can't think of anything, we should |
9e5b9ab
to
f366227
Compare
anyone else have thoughts here? someone wanna approve this? |
📌 Commit f366227 has been approved by |
@bors rollup |
…Sushi Document behavior of `ptr::swap` with overlapping regions of memory. Fixes rust-lang#44479.
Fixes #44479.