-
Notifications
You must be signed in to change notification settings - Fork 13.3k
extend from_raw_parts docs for slices and strs to mention alignment requirement #51134
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
The changes to |
@rust-highfive seems to be on vacation? |
str::from_raw_parts has been removed long ago because it can be obtained via str::from_utf8_unchecked and slice::from_raw_parts. The same goes for str::from_raw_parts_mut.
Oh, good point.
Done. |
r? @SimonSapin (@rust-highfive somehow missed this PR so I picked someone from the libs team...) |
@bors r+ |
📌 Commit b30aaf2 has been approved by |
extend from_raw_parts docs for slices and strs to mention alignment requirement The documentation for `str::from_raw_parts_mut` seems to not be visible because that method is private, bit I figured it could still be fixed. I also removed the reference to the no-longer-existing `str::from_raw_parts` while I was at it. Alternatively, should I remove `str::from_raw_parts_mut` completely? it is only used in `str::split_at_mut`, where it might as well be inlined.
☀️ Test successful - status-appveyor, status-travis |
It's good that this change documented the new alignment requirement. Thanks. It's unfortunate that it also removed the explanation why the pointer has to be non-null. (People are more likely to obey the rules when they understand the rationale.) |
The problem is that enum layout optimizations currently only exploit non-nullness, not alignment -- and it seemed weird to me to provide explanation for some but not all of the requirements. We could mention the arcane LLVM flags we are setting (both for nunnull and aligned), but I don't feel that would explain anything. The thing is, even if the layout optimizations were turned off, it'd still be UB due to these flags. |
The documentation for
str::from_raw_parts_mut
seems to not be visible because that method is private, bit I figured it could still be fixed. I also removed the reference to the no-longer-existingstr::from_raw_parts
while I was at it.Alternatively, should I remove
str::from_raw_parts_mut
completely? it is only used instr::split_at_mut
, where it might as well be inlined.