From: "Benno Lossin" <lossin@kernel.org>
To: "Gary Guo" <gary@garyguo.net>, "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Fiona Behrens" <me@kloenk.dev>,
"Christian Schrefl" <chrisi.schrefl@gmail.com>,
"Alban Kurti" <kurti@invicto.ai>
Cc: <linux-kernel@vger.kernel.org>, <rust-for-linux@vger.kernel.org>
Subject: Re: [PATCH 08/12] rust: pin-init: rewrite the initializer macros using `syn`
Date: Fri, 09 Jan 2026 18:24:37 +0100 [thread overview]
Message-ID: <DFK8F3L2BMS2.3G1BAQSU145IH@kernel.org> (raw)
In-Reply-To: <DFK3R2EK1JGL.FFW73JGUSGP5@garyguo.net>
On Fri Jan 9, 2026 at 2:45 PM CET, Gary Guo wrote:
> On Thu Jan 8, 2026 at 1:50 PM GMT, Benno Lossin wrote:
>> + let init_kind = get_init_kind(rest, &mut errors);
>> + let zeroable_check = match init_kind {
>> + InitKind::Normal => quote!(),
>> + InitKind::Zeroing => quote! {
>> + // The user specified `..Zeroable::zeroed()` at the end of the list of fields.
>> + // Therefore we check if the struct implements `Zeroable` and then zero the memory.
>> + // This allows us to also remove the check that all fields are present (since we
>> + // already set the memory to zero and that is a valid bit pattern).
>> + fn assert_zeroable<T: ?::core::marker::Sized>(_: *mut T)
>> + where T: ::pin_init::Zeroable
>> + {}
>> + // Ensure that the struct is indeed `Zeroable`.
>> + assert_zeroable(#slot);
>> + // SAFETY: The type implements `Zeroable` by the check above.
>> + unsafe { ::core::ptr::write_bytes(#slot, 0, 1) };
>
> Can this be `#slot.write(::pin_init::zeroed())`?
That could overflow the stack?
>> + },
>> + };
>> + InitKind::Zeroing => quote! {
>> + // We use unreachable code to ensure that all fields have been mentioned at most once.
>> + // Since the user specified `..Zeroable::zeroed()` at the end, all missing fields will
>> + // be zeroed. This struct initializer will still be type-checked and complain with a
>> + // very natural error message if a field is mentioned more than once, or doesn't exist.
>> + #[allow(unreachable_code, clippy::diverging_sub_expression, unused_assignments)]
>> + // SAFETY: this code is never executed.
>> + let _ = || unsafe {
>> + let mut zeroed = ::core::mem::zeroed();
>> + ::core::ptr::write(slot, zeroed);
>
> Looks like the comment explaining why this is done gets missed.
Good catch!
>> + zeroed = ::core::mem::zeroed();
>> + ::core::ptr::write(slot, #path {
>> + #(
>> + #fields: ::core::panic!(),
>> + )*
>> + ..zeroed
>
> Would just ::core::mem::zeroed() here work or does it have same inference issue?
> IIUC the type inference should work here as ..Default::default() works.
I haven't checked this, will do so.
Cheers,
Benno
next prev parent reply other threads:[~2026-01-09 17:24 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-08 13:50 [PATCH 00/13] `syn` rewrite of pin-init Benno Lossin
2026-01-08 13:50 ` [PATCH 01/12] rust: pin-init: remove `try_` versions of the initializer macros Benno Lossin
2026-01-08 13:50 ` [PATCH 02/12] rust: pin-init: allow the crate to refer to itself as `pin-init` in doc tests Benno Lossin
2026-01-08 13:50 ` [PATCH 03/12] rust: pin-init: add `syn` dependency and remove `proc-macro[2]` and `quote` workarounds Benno Lossin
2026-01-08 13:50 ` [PATCH 04/12] rust: pin-init: rewrite `derive(Zeroable)` and `derive(MaybeZeroable)` using `syn` Benno Lossin
2026-01-09 12:02 ` Gary Guo
2026-01-08 13:50 ` [PATCH 05/12] rust: pin-init: rewrite the `#[pinned_drop]` attribute macro " Benno Lossin
2026-01-09 12:12 ` Gary Guo
2026-01-09 15:34 ` Benno Lossin
2026-01-09 16:42 ` Gary Guo
2026-01-08 13:50 ` [PATCH 06/12] rust: pin-init: rewrite `#[pin_data]` " Benno Lossin
2026-01-09 7:45 ` kernel test robot
2026-01-09 12:47 ` Gary Guo
2026-01-09 16:39 ` Benno Lossin
2026-01-09 16:46 ` Gary Guo
2026-01-10 16:41 ` Benno Lossin
2026-01-10 19:18 ` Gary Guo
2026-01-08 13:50 ` [PATCH 07/12] rust: pin-init: add `?Sized` bounds to traits in `#[pin_data]` macro Benno Lossin
2026-01-08 13:50 ` [PATCH 08/12] rust: pin-init: rewrite the initializer macros using `syn` Benno Lossin
2026-01-09 8:44 ` kernel test robot
2026-01-09 13:45 ` Gary Guo
2026-01-09 17:24 ` Benno Lossin [this message]
2026-01-10 16:21 ` Benno Lossin
2026-01-10 18:14 ` Benno Lossin
2026-01-10 19:20 ` Gary Guo
2026-01-10 23:18 ` Benno Lossin
2026-01-11 1:10 ` Gary Guo
2026-01-11 10:04 ` Benno Lossin
2026-01-08 13:50 ` [PATCH 09/12] rust: pin-init: add `#[default_error(<type>)]` attribute to initializer macros Benno Lossin
2026-01-09 13:52 ` Gary Guo
2026-01-08 13:50 ` [PATCH 10/12] rust: init: use `#[default_error(err)]` for the " Benno Lossin
2026-01-08 13:50 ` [PATCH 11/12] rust: pin-init: internal: init: add support for attributes on initializer fields Benno Lossin
2026-01-09 13:55 ` Gary Guo
2026-01-09 18:02 ` Benno Lossin
2026-01-09 21:16 ` Gary Guo
2026-01-08 13:50 ` [PATCH 12/12] rust: pin-init: internal: init: add escape hatch for referencing initialized fields Benno Lossin
2026-01-09 9:44 ` kernel test robot
2026-01-09 13:58 ` Gary Guo
2026-01-09 18:04 ` Benno Lossin
2026-01-08 13:50 ` [PATCH 13/13] MAINTAINERS: add Gary Guo to pin-init Benno Lossin
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=DFK8F3L2BMS2.3G1BAQSU145IH@kernel.org \
--to=lossin@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=chrisi.schrefl@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=kurti@invicto.ai \
--cc=linux-kernel@vger.kernel.org \
--cc=me@kloenk.dev \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.