Skip to content

Commit 205a718

Browse files
rust: Eschew Box<MaybeUninit<T>>::write
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]>
1 parent 6d1c22d commit 205a718

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

rust/kernel/alloc/box_ext.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ pub trait BoxExt<T>: Sized {
3737

3838
impl<T> BoxExt<T> for Box<T> {
3939
fn new(x: T, flags: Flags) -> Result<Self, AllocError> {
40-
let b = <Self as BoxExt<_>>::new_uninit(flags)?;
41-
Ok(Box::write(b, x))
40+
let mut b = <Self as BoxExt<_>>::new_uninit(flags)?;
41+
b.write(x);
42+
// SAFETY: We just wrote to it.
43+
Ok(unsafe { b.assume_init() })
4244
}
4345

4446
#[cfg(any(test, testlib))]

0 commit comments

Comments
 (0)