Skip to content

Commit

Permalink
rust: Eschew Box<MaybeUninit<T>>::write
Browse files Browse the repository at this point in the history
T-libs-api has consensus for stabilizing some of `feature(new_uninit)`,
but not for `Box<MaybeUninit<T>>::write`. The replacement is trivial, so
let's just do that, and RfL can simply move off the feature after it is
stabilized. That will happen immediately after this unblocks Rust CI,
as the relevant FCP has completed:

rust-lang/rust#63291 (comment)

This is required in advance of the stabilization because any remaining
unstable API will be carved up into subfeatures as a direct result of
stabilizing the majority of it. This code doesn't know about those yet.
It can't, as they haven't landed, as building this code blocks Rust's CI
but the expected-to-be-stabilized API can't be stabilized as long as
this code requires that feature.

Signed-off-by: Jubilee Young <[email protected]>
  • Loading branch information
workingjubilee committed Aug 22, 2024
1 parent 6d1c22d commit 5f368ed
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions rust/kernel/alloc/box_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ pub trait BoxExt<T>: Sized {

impl<T> BoxExt<T> for Box<T> {
fn new(x: T, flags: Flags) -> Result<Self, AllocError> {
let b = <Self as BoxExt<_>>::new_uninit(flags)?;
Ok(Box::write(b, x))
let mut b = <Self as BoxExt<_>>::new_uninit(flags)?;
b.write(x);
Ok(unsafe { b.assume_init() })
}

#[cfg(any(test, testlib))]
Expand Down

0 comments on commit 5f368ed

Please sign in to comment.