-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Use raw pointers to avoid aliasing in str::split_at_mut #31052
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
Conversation
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
Use raw pointers to avoid aliasing in str::split_at_mut Introduce private functions from_raw_parts, from_raw_parts_mut for str to factor out the logic. We want to use raw pointers here instead of duplicating a &mut str, to be on safer ground w.r.t rust aliasing rules. This has already been fixed for slices in PR #27358, issue #27357
💔 Test failed - auto-win-msvc-64-opt |
Oh wow, an interesting build failure. I have to suspect that the
|
Introduce private function from_raw_parts_mut for str to factor out the logic. We want to use raw pointers here instead of duplicating a &mut str, to be on safer ground w.r.t rust aliasing rules.
8d71ca5
to
ba9a3bc
Compare
PR revision: I removed the changes to slice_unchecked, slice_unchecked_mut. |
/// str is returned. | ||
/// | ||
unsafe fn from_raw_parts_mut<'a>(p: *mut u8, len: usize) -> &'a mut str { | ||
mem::transmute::<&mut [u8], &mut str>(slice::from_raw_parts_mut(p, len)) |
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.
transmute
-> from_utf8_unchecked
?
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.
Needs a _mut version. I could add that.
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.
Should I? Always quicker to avoid having to champion new public API for example.
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 would personally prefer to stabilize from_utf8_unchecked_mut
than from_raw_parts_mut
, but I don't think we necessarily need the function just yet so I would be fine just leaving this as -is.
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 is a good plan for the future.
The commit how it looked when causing the interesting error https://gist.github.com/bluss/0f0f90c0b5b7ec5789d4 Edit: Wrong version. fixed. |
Use raw pointers to avoid aliasing in str::split_at_mut Introduce private function from_raw_parts_mut for str to factor out the logic. We want to use raw pointers here instead of duplicating a &mut str, to be on safer ground w.r.t rust aliasing rules. This has already been fixed for slices in PR #27358, issue #27357
Use raw pointers to avoid aliasing in str::split_at_mut
Introduce private function from_raw_parts_mut for str to factor out the logic.
We want to use raw pointers here instead of duplicating a &mut str, to
be on safer ground w.r.t rust aliasing rules.
This has already been fixed for slices in PR #27358, issue #27357