Skip to content
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

Merged
merged 1 commit into from
Jan 22, 2021
Merged

use raw-ptr-addr-of for slice::swap #81160

merged 1 commit into from
Jan 22, 2021

Conversation

RalfJung
Copy link
Member

Fixes #80682

@rust-highfive
Copy link
Collaborator

r? @kennytm

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 18, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Jan 18, 2021

r? @oli-obk

@bors r+

@rust-highfive rust-highfive assigned oli-obk and unassigned kennytm Jan 18, 2021
@bors
Copy link
Contributor

bors commented Jan 18, 2021

📌 Commit dc04cea has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 18, 2021
@oli-obk oli-obk added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Jan 18, 2021
m-ou-se added a commit to m-ou-se/rust that referenced this pull request Jan 18, 2021
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]);
Copy link
Member

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 (?)

Copy link
Contributor

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.

@bors
Copy link
Contributor

bors commented Jan 22, 2021

⌛ Testing commit dc04cea with merge a9a396d...

@bors
Copy link
Contributor

bors commented Jan 22, 2021

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing a9a396d to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

slice::swap violates the aliasing rules
7 participants