From: Jubilee Young <workingjubilee@gmail.com>
To: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@samsung.com>,
"Alice Ryhl" <aliceryhl@google.com>
Cc: rust-for-linux@vger.kernel.org, Jubilee Young <workingjubilee@gmail.com>
Subject: [PATCH] rust: Eschew `Box<MaybeUninit<T>>::write`
Date: Thu, 22 Aug 2024 22:03:59 -0700 [thread overview]
Message-ID: <20240823050359.1737893-1-workingjubilee@gmail.com> (raw)
T-libs-api has consensus for stabilizing some of `feature(new_uninit)`,
but not for `Box<MaybeUninit<T>>::write`. Instead, we can use
`MaybeUninit<T>::write`, so Rust for Linux can drop the feature after
stabilization. That will happen after merging, as the FCP has completed:
https://github.com/rust-lang/rust/issues/63291#issuecomment-2183022955
This is required before stabilization because remaining-unstable API
will be divided into new features. This code doesn't know about those
yet. It can't: they haven't landed, as the relevant PR is blocked on
rustc's CI testing Rust-for-Linux without this patch.
Signed-off-by: Jubilee Young <workingjubilee@gmail.com>
---
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 b68ade26a42d..6179d893ff3a 100644
--- a/rust/kernel/alloc/box_ext.rs
+++ b/rust/kernel/alloc/box_ext.rs
@@ -37,8 +37,10 @@ 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);
+ // SAFETY: We just wrote to it.
+ Ok(unsafe { b.assume_init() })
}
#[cfg(any(test, testlib))]
--
2.45.2
next reply other threads:[~2024-08-23 5:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-23 5:03 Jubilee Young [this message]
2024-08-23 5:44 ` [PATCH] rust: Eschew `Box<MaybeUninit<T>>::write` Trevor Gross
2024-08-23 6:11 ` Miguel Ojeda
2024-08-23 6:24 ` Trevor Gross
2024-08-23 11:23 ` Miguel Ojeda
2024-08-23 11:10 ` Alice Ryhl
2024-08-23 11:23 ` Miguel Ojeda
2024-08-27 7:34 ` Miguel Ojeda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240823050359.1737893-1-workingjubilee@gmail.com \
--to=workingjubilee@gmail.com \
--cc=a.hindborg@samsung.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=wedsonaf@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox