rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benno Lossin <benno.lossin@proton.me>
To: Laine Taffin Altman <alexanderaltman@me.com>,
	Boqun Feng <boqun.feng@gmail.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Wedson Almeida Filho" <wedsonaf@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Andreas Hindborg" <a.hindborg@samsung.com>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Martin Rodriguez Reboredo" <yakoyoku@gmail.com>,
	stable@vger.kernel.org, rust-for-linux@vger.kernel.org,
	lkml <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] rust: init: remove impl Zeroable for Infallible
Date: Tue, 19 Mar 2024 10:34:01 +0000	[thread overview]
Message-ID: <6857bb37-c4ee-4817-9b6a-e40e549b6402@proton.me> (raw)
In-Reply-To: <3FBC841A-968E-4AC5-83F0-E906C7EE85C3@me.com>

On 3/19/24 06:28, Laine Taffin Altman wrote:
> On Mar 18, 2024, at 9:39 PM, Boqun Feng <boqun.feng@gmail.com> wrote:
>> On Mon, Mar 18, 2024 at 08:17:07PM -0700, Laine Taffin Altman wrote:
>>> On Mar 18, 2024, at 10:25 AM, Boqun Feng <boqun.feng@gmail.com> wrote:
>>>> On Wed, Mar 13, 2024 at 11:09:37PM +0000, Benno Lossin wrote:
>>>>> From: Laine Taffin Altman <alexanderaltman@me.com>
>>>>>
>>>>> It is not enough for a type to be a ZST to guarantee that zeroed memory
>>>>> is a valid value for it; it must also be inhabited. Creating a value of
>>>>> an uninhabited type, ZST or no, is immediate UB.
>>>>> Thus remove the implementation of `Zeroable` for `Infallible`, since
>>>>> that type is not inhabited.
>>>>>
>>>>> Cc: stable@vger.kernel.org
>>>>> Fixes: 38cde0bd7b67 ("rust: init: add `Zeroable` trait and `init::zeroed` function")
>>>>> Closes: https://github.com/Rust-for-Linux/pinned-init/pull/13
>>>>> Signed-off-by: Laine Taffin Altman <alexanderaltman@me.com>
>>>>> Signed-off-by: Benno Lossin <benno.lossin@proton.me>
>>>>
>>>> I think either in the commit log or in the code comment, there better be
>>>> a link or explanation on "(un)inhabited type". The rest looks good to
>>>> me.
>>>
>>> Would the following be okay for that purpose?
>>>
>>> A type is inhabited if at least one valid value of that type exists; a
>>> type is uninhabited if no valid values of that type exist.  The terms
>>> "inhabited" and "uninhabited" in this sense originate in type theory,
>>> a branch of mathematics.
>>>
>>> In Rust, producing an invalid value of any type is immediate undefined
>>> behavior (UB); this includes via zeroing memory.  Therefore, since an
>>> uninhabited type has no valid values, producing any values at all for
>>> it is UB.
>>>
>>> The Rust standard library type `core::convert::Infallible` is
>>> uninhabited, by virtue of having been declared as an enum with no
>>> cases, which always produces uninhabited types in Rust.  Thus, remove
>>> the implementation of `Zeroable` for `Infallible`, thereby avoiding
>>> the UB.
>>>
>>
>> Yeah, this works for me. Thanks!
> 
> Great!  Should it be re-sent or can the new wording be incorporated upon merge?

I can re-send it for you again, or do you want to send it yourself?
I think it is also a good idea to add a link to [1] in the code, since
the above explanation is rather long and fits better in the commit
message.

-- 
Cheers,
Benno

[1]: https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types


  reply	other threads:[~2024-03-19 10:34 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-13 23:09 [PATCH] rust: init: remove impl Zeroable for Infallible Benno Lossin
2024-03-14  9:14 ` Alice Ryhl
2024-03-18 17:25 ` Boqun Feng
2024-03-19  3:17   ` Laine Taffin Altman
2024-03-19  4:39     ` Boqun Feng
2024-03-19  5:28       ` Laine Taffin Altman
2024-03-19 10:34         ` Benno Lossin [this message]
2024-03-19 11:24           ` Miguel Ojeda
2024-03-21  4:53           ` Laine Taffin Altman
2024-03-21  9:07             ` Miguel Ojeda
2024-03-30 12:03             ` Benno Lossin
2024-03-30 16:36               ` Laine Taffin Altman
2024-03-30 16:43                 ` 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=6857bb37-c4ee-4817-9b6a-e40e549b6402@proton.me \
    --to=benno.lossin@proton.me \
    --cc=a.hindborg@samsung.com \
    --cc=alex.gaynor@gmail.com \
    --cc=alexanderaltman@me.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=wedsonaf@gmail.com \
    --cc=yakoyoku@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;
as well as URLs for NNTP newsgroup(s).