From 205a71892c13fe5fa1d04f4214147feea7de06c4 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Thu, 22 Aug 2024 16:04:56 -0700 Subject: [PATCH] rust: Eschew `Box>::write` T-libs-api has consensus for stabilizing some of `feature(new_uninit)`, but not for `Box>::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: https://github.com/rust-lang/rust/issues/63291#issuecomment-2183022955 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 --- rust/kernel/alloc/box_ext.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rust/kernel/alloc/box_ext.rs b/rust/kernel/alloc/box_ext.rs index b68ade26a42dd0..6179d893ff3aa8 100644 --- a/rust/kernel/alloc/box_ext.rs +++ b/rust/kernel/alloc/box_ext.rs @@ -37,8 +37,10 @@ pub trait BoxExt: Sized { impl BoxExt for Box { fn new(x: T, flags: Flags) -> Result { - let b = >::new_uninit(flags)?; - Ok(Box::write(b, x)) + let mut b = >::new_uninit(flags)?; + b.write(x); + // SAFETY: We just wrote to it. + Ok(unsafe { b.assume_init() }) } #[cfg(any(test, testlib))]