-
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
ptr::swap docs needs clarfication #44479
Comments
Nominating for @rust-lang/libs discussion about what behavior to spec; then @rust-lang/docs is happy to doc whatever they decide. |
I am okay with the current behavior. Agree the doc should explain what happens. |
Discussed during libs triage the conclusion was "let's do what C++ does", there weren't any particular strong opinions. |
Seems like this might be resolved by #43964? |
No that's where the issue was raised. I didn't want to block the PR on a pre-existing issue. |
i'd be happy to take care of this
to clarify, does C++ do the 'LHS winning' behavior that @gankro mentioned in the original description of this issue? and if so, does C++ specify this behavior somewhere? |
opened a PR for this, would appreciate if one of y'all could take a look: #46483 |
…Sushi Document behavior of `ptr::swap` with overlapping regions of memory. Fixes rust-lang#44479.
The docs state that overlap is permitted, which is intended to cover the lhs==rhs case, but don't specify what that means for partial overlap. For instance:
Reasonable implementations are forced to produce either 0 or 2 for the middle value. We should definitely at least spec that that happens. If we want to be Extra Helpful, we can specify that 0 is used, because there's basically no reason to change this behaviour, or for a different impl to diverge.
Something like "if the LHS and RHS overlap, then the overlapping region of memory will be derived from the LHS", along with the above example to clarify.
A nice thing about specifying it is that, because it's otherwise symmetric, you can swap your lhs/rhs to choose exactly which half you want to "win".
The text was updated successfully, but these errors were encountered: