-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Add inherent versions of MaybeUninit methods for slices #129259
Conversation
a88bac8
to
b3cf03f
Compare
This comment has been minimized.
This comment has been minimized.
The implementation looks pretty reasonable to me, but as this is an API decision: r? libs-api Is the intent here to replace the existing |
I decided to not delete them since so many people are using these methods, but I can deprecate them depending on what people think is best. |
b3cf03f
to
ecb920d
Compare
This comment has been minimized.
This comment has been minimized.
ecb920d
to
45caae8
Compare
This comment has been minimized.
This comment has been minimized.
0cd81e0
to
6641ecd
Compare
This comment has been minimized.
This comment has been minimized.
We discussed this in the libs-api meeting. We're happy with these changes, but we would also like to see similar changes for the Also, the old methods on |
Based on the above it seems like there are a few updates needed here. @rustbot author |
6641ecd
to
ea647ca
Compare
This comment has been minimized.
This comment has been minimized.
ea647ca
to
74fcbfb
Compare
This comment has been minimized.
This comment has been minimized.
Ah you know actually sorry, the change from Maybe it's easiest to move the @bors r- |
Figured it makes more sense to pong this back to libs-api than mark it as my review, since libs-api did want to include these methods in the final PR. r? libs-api |
@clarfonthey any chance you are willing to reconsider moving Just asking because I'd like to start using this new API :) |
I mean, if you're cool merging this as-is without the fill methods, I'm fine splitting it. Just want to clarify which methods should be left in and which are left out. |
Specifically the changes |
981936b
to
e37daf0
Compare
Rebased and locally tested, but will wait for CI to pass before calling this officially ready. Moved the second half of the PR to #135394. |
Should be ready to merge! |
🎉 @bors r+ |
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#129259 (Add inherent versions of MaybeUninit methods for slices) - rust-lang#135374 (Suggest typo fix when trait path expression is typo'ed) - rust-lang#135377 (Make MIR cleanup for functions with impossible predicates into a real MIR pass) - rust-lang#135378 (Remove a bunch of diagnostic stashing that doesn't do anything) - rust-lang#135397 (compiletest: add erroneous variant to `string_enum`s conversions error) - rust-lang#135398 (add more crash tests) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#129259 - clarfonthey:maybe_uninit_slices, r=tgross35 Add inherent versions of MaybeUninit methods for slices This is my attempt to un-stall rust-lang#63569 and rust-lang#79995, by creating methods that mirror the existing `MaybeUninit` API: ```rust impl<T> MaybeUninit<T> { pub fn write(&mut self, value: T) -> &mut T; pub fn as_bytes(&self) -> &[MaybeUninit<u8>]; pub fn as_bytes_mut(&mut self) -> &mut [MaybeUninit<u8>]; pub unsafe fn assume_init_drop(&mut self); pub unsafe fn assume_init_ref(&self) -> &T; pub unsafe fn assume_init_mut(&mut self) -> &mut T; } ``` Adding these APIs: ```rust impl<T> [MaybeUninit<T>] { // replacing copy_from_slice; renamed to avoid conflict pub fn write_copy_of_slice(&mut self, value: &[T]) -> &mut [T] where T: Copy; // replacing clone_from_slice; renamed to avoid conflict pub fn write_clone_of_slice(&mut self, value: &[T]) -> &mut [T] where T: Clone; // identical to non-slice versions; no conflict pub fn as_bytes(&self) -> &[MaybeUninit<u8>]; pub fn as_bytes_mut(&mut self) -> &mut [MaybeUninit<u8>]; pub unsafe fn assume_init_drop(&mut self); pub unsafe fn assume_init_ref(&self) -> &[T]; pub unsafe fn assume_init_mut(&mut self) -> &mut [T]; } ``` Since the `assume_init` methods are identical to those on non-slices, they feel pretty natural. The main issue with the write methods is naming, as discussed in rust-lang#79995 among other places. My rationale: * The term "write" should be in them somewhere, to mirror the other API, and this pretty much automatically makes them not collide with any other inherent slice methods. * I chose `write_clone_of_slice` and `write_copy_of_slice` since `clone` and `copy` are being used as objects here, whereas they're being used as actions in `clone_from_slice` and `copy_from_slice`. The final "weird" thing I've done in this PR is remove a link to `Vec<T>` from `assume_init_drop` (both copies, since they're effectively copied docs), since there's no good way to link to `Vec` for something that can occur both on the page for `std/primitive.slice.html` and `std/vec/struct.Vec.html`, since the code here lives in libcore and can't use intra-doc-linking to mention `Vec`. (see: rust-lang#121436) The reason why this method shows up both on `Vec<T>` and `[T]` is because the `[T]` docs are automatically inlined on `Vec<T>`'s page, since it implements `Deref`. It's unfortunate that rustdoc doesn't have a way of dealing with this at the moment, but it is what it is, and it's a reasonable compromise for now.
This is my attempt to un-stall #63569 and #79995, by creating methods that mirror the existing
MaybeUninit
API:Adding these APIs:
Since the
assume_init
methods are identical to those on non-slices, they feel pretty natural. The main issue with the write methods is naming, as discussed in #79995 among other places. My rationale:write_clone_of_slice
andwrite_copy_of_slice
sinceclone
andcopy
are being used as objects here, whereas they're being used as actions inclone_from_slice
andcopy_from_slice
.The final "weird" thing I've done in this PR is remove a link to
Vec<T>
fromassume_init_drop
(both copies, since they're effectively copied docs), since there's no good way to link toVec
for something that can occur both on the page forstd/primitive.slice.html
andstd/vec/struct.Vec.html
, since the code here lives in libcore and can't use intra-doc-linking to mentionVec
. (see: #121436)The reason why this method shows up both on
Vec<T>
and[T]
is because the[T]
docs are automatically inlined onVec<T>
's page, since it implementsDeref
. It's unfortunate that rustdoc doesn't have a way of dealing with this at the moment, but it is what it is, and it's a reasonable compromise for now.