From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Lorenzo Delgado" <lnsdev@proton.me>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"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>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Onur Özkan" <work@onurozkan.dev>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
"Thorsten Blum" <blum@kernel.org>,
"Francis Laniel" <laniel_francis@npnm.eu>
Subject: Re: [PATCH v3 0/2] rust: add NonEmpty
Date: Thu, 15 Oct 2026 21:57:00 +0900 [thread overview]
Message-ID: <DM5FG6VMG3U7.1XMZW8RJI2KLM@nvidia.com> (raw)
In-Reply-To: <20261013-nonempty-slice-v3-0-4463cc0338f8@proton.me>
On Wed Oct 14, 2026 at 5:30 PM JST, Lorenzo Delgado wrote:
> Some functions check that a container is not empty and later rely on it
> through `unwrap_unchecked()`, `unwrap()` or an error path that can't be
> taken. Gary suggested a non-empty type for this while reviewing Thorsten
> Blum's uaccess patch [1], and Miguel filed it as #1262 [2].
>
> Patch 1 adds `NonEmpty<C>` in `kernel::non_empty`, with only what the
> first user needs: slices, `try_from_mut()`, `from_mut()` for arrays
> and `last_mut()`. Patch 2 makes `strcpy_into_buf()` take a
> `NonEmpty<[u8]>`, which drops an `unsafe` block and the `EINVAL` case.
>
> Some notes:
>
> - `IsEmpty` is a safe trait. Unsafe code only relies on the
> implementations in `kernel::non_empty`, and the docs require the
> result not to change while the container is only reachable through a
> shared reference. If a generic accessor ever needs to rely on it, it
> can become an `unsafe trait` then.
>
> - Since APIs aren't added without users, other accessors (`first()`,
> `try_from_ref()`, ...) and containers are left for later. I plan to
> send follow-ups for `net/phy.rs` and `scatterlist.rs`, which both
> reject an empty slice and then rely on it.
Having `last` without `first` is weird. Please add the minimal set that
makes sense from the get-go, these are `pub` anyway so clippy won't
complain if they are unused.
>
> - I put it in its own `kernel::non_empty` module. Would a broader home
> like `kernel::collections` be better?
`kernel::types` sounds like a proper place? Or if we want a dedicated
module, `kernel::slice` to match the standard library? `non_empty` is
too ad-hoc and specific.
Also as a general comment: the commit messages and comments read as
LLM-generated and are insufferably mechanical and tedious. Please turn
the LLM dial down a bit and spend some time writing or at least editing
them yourself to save some time for your reviewers. The doccomment for
`from_mut` is a good example of something that could be reduced to 2
lines max.
next prev parent reply other threads:[~2026-10-15 12:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 8:30 [PATCH v3 0/2] rust: add NonEmpty Lorenzo Delgado
2026-10-14 8:30 ` [PATCH v3 1/2] rust: non_empty: " Lorenzo Delgado
2026-10-14 11:55 ` Miguel Ojeda
2026-10-14 14:25 ` Gary Guo
2026-10-15 12:43 ` Alexandre Courbot
2026-10-15 14:02 ` Gary Guo
2026-10-15 14:33 ` Alexandre Courbot
2026-10-15 14:08 ` Miguel Ojeda
2026-10-14 8:30 ` [PATCH v3 2/2] rust: uaccess: use NonEmpty in strcpy_into_buf() Lorenzo Delgado
2026-10-15 13:06 ` Alexandre Courbot
2026-10-15 14:04 ` Gary Guo
2026-10-15 12:57 ` Alexandre Courbot [this message]
2026-10-15 14:08 ` [PATCH v3 0/2] rust: add NonEmpty Gary Guo
2026-10-15 14:11 ` Miguel Ojeda
2026-10-15 14:35 ` Alexandre Courbot
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=DM5FG6VMG3U7.1XMZW8RJI2KLM@nvidia.com \
--to=acourbot@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=blum@kernel.org \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=laniel_francis@npnm.eu \
--cc=linux-kernel@vger.kernel.org \
--cc=lnsdev@proton.me \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/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.