mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Gary Guo" <gary@garyguo.net>, "Alexandre Courbot" <acourbot@nvidia.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"John Hubbard" <jhubbard@nvidia.com>,
	"Alistair Popple" <apopple@nvidia.com>,
	"Joel Fernandes" <joelagnelf@nvidia.com>,
	"Timur Tabi" <ttabi@nvidia.com>, "Edwin Peer" <epeer@nvidia.com>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] rust: transmute: implement FromBytes and AsBytes for ()
Date: Tue, 09 Dec 2025 11:39:47 +0900	[thread overview]
Message-ID: <DETC6QG6AT7A.2OPSK3M0G90SG@nvidia.com> (raw)
In-Reply-To: <20251208132708.4acbc440.gary@garyguo.net>

On Mon Dec 8, 2025 at 10:27 PM JST, Gary Guo wrote:
> On Mon, 08 Dec 2025 18:54:40 +0900
> Alexandre Courbot <acourbot@nvidia.com> wrote:
>
>> This is useful when using types that may or may not be empty in generic
>> code relying on these traits. It is also safe because technically a
>> no-op.
>> 
>> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
>> ---
>>  rust/kernel/transmute.rs | 6 ++++++
>>  1 file changed, 6 insertions(+)
>> 
>> diff --git a/rust/kernel/transmute.rs b/rust/kernel/transmute.rs
>> index be5dbf3829e2..8d78c81e3749 100644
>> --- a/rust/kernel/transmute.rs
>> +++ b/rust/kernel/transmute.rs
>> @@ -170,6 +170,9 @@ macro_rules! impl_frombytes {
>>  }
>>  
>>  impl_frombytes! {
>> +    // SAFETY: This type is empty and thus does not consume any data.
>> +    (),
>
> I'd avoid use the word "empty" as it has the meaning of uninhabited
> types (never type) in type theory. ZSTs that are inhabited are unit
> types (or singletons).
>
>
> Perhaps better to have a justification that applies to all inhabited
> ZSTs that don't have special semantics. Something like this?
>
> 	// SAFETY: Inhabited ZSTs only have one possible bit pattern.
> 	(),
> 	{<T>} PhantomData<T>,

Sounds good - I'll use your SAFETY statement as-is. Adding `PhantomData`
is also a great idea.

Thanks for the review!

  reply	other threads:[~2025-12-09  2:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-08  9:54 [PATCH v2 0/2] " Alexandre Courbot
2025-12-08  9:54 ` [PATCH v2 1/2] " Alexandre Courbot
2025-12-08 11:00   ` Alistair Popple
2025-12-08 13:27   ` Gary Guo
2025-12-09  2:39     ` Alexandre Courbot [this message]
2025-12-08  9:54 ` [PATCH v2 2/2] gpu: nova-core: gsp: use () as message type for GspInitDone message Alexandre Courbot
2025-12-08 10:56   ` Alistair Popple

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=DETC6QG6AT7A.2OPSK3M0G90SG@nvidia.com \
    --to=acourbot@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=epeer@nvidia.com \
    --cc=gary@garyguo.net \
    --cc=jhubbard@nvidia.com \
    --cc=joelagnelf@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    --cc=ttabi@nvidia.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

all inboxes | Powered by JetHome®