-
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
use raw-ptr-addr-of for slice::swap #81160
Conversation
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
📌 Commit dc04cea has been approved by |
use raw-ptr-addr-of for slice::swap Fixes rust-lang#80682
let pb: *mut T = &mut self[b]; | ||
// Can't take two mutable loans from one vector, so instead use raw pointers. | ||
let pa = ptr::raw_mut!(self[a]); | ||
let pb = ptr::raw_mut!(self[b]); |
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'm just curious - the reason that this works, is that we use intrinsic indexing of the slice? If we would go through IndexMut
, the problem wouldn't be solved (?)
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.
Yes, indexing a slice directly translates to a MIR instruction without any function calls. This is the same as what we do for arithmetic operators for primitive integers. The trait impls only exist for the type system and generics.
☀️ Test successful - checks-actions |
Fixes #80682