[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <DD52ZFG2MKAL.35RFN8L4LH5H1@nvidia.com>
Date: Mon, 29 Sep 2025 15:47:08 +0900
From: "Alexandre Courbot" <acourbot@...dia.com>
To: "Joel Fernandes" <joelagnelf@...dia.com>,
<linux-kernel@...r.kernel.org>, <rust-for-linux@...r.kernel.org>,
<dri-devel@...ts.freedesktop.org>, <dakr@...nel.org>, <acourbot@...dia.com>
Cc: "Alistair Popple" <apopple@...dia.com>, "Miguel Ojeda"
<ojeda@...nel.org>, "Alex Gaynor" <alex.gaynor@...il.com>, "Boqun Feng"
<boqun.feng@...il.com>, "Gary Guo" <gary@...yguo.net>,
<bjorn3_gh@...tonmail.com>, "Benno Lossin" <lossin@...nel.org>, "Andreas
Hindborg" <a.hindborg@...nel.org>, "Alice Ryhl" <aliceryhl@...gle.com>,
"Trevor Gross" <tmgross@...ch.edu>, "David Airlie" <airlied@...il.com>,
"Simona Vetter" <simona@...ll.ch>, "Maarten Lankhorst"
<maarten.lankhorst@...ux.intel.com>, "Maxime Ripard" <mripard@...nel.org>,
"Thomas Zimmermann" <tzimmermann@...e.de>, "John Hubbard"
<jhubbard@...dia.com>, "Timur Tabi" <ttabi@...dia.com>,
<joel@...lfernandes.org>, "Elle Rhumsaa" <elle@...thered-steel.dev>, "Yury
Norov" <yury.norov@...il.com>, "Daniel Almeida"
<daniel.almeida@...labora.com>, <nouveau@...ts.freedesktop.org>
Subject: Re: [PATCH v4 6/6] rust: bitfield: Use 'as' operator for setter
type conversion
On Sun Sep 21, 2025 at 3:22 AM JST, Joel Fernandes wrote:
> The bitfield macro's setter currently uses the From trait for type
> conversion, which is overly restrictive and prevents use cases such as
> narrowing conversions (e.g., u32 storage size to u8 field size) which
> aren't supported by From.
>
> Replace 'from' with 'as' in the setter implementation to support this.
>
> Suggested-by: Yury Norov <yury.norov@...il.com>
Can you add a `Link: ` tag to the discussion for context?
But I am not really convinced this is needed or desirable at all. Where
would it make sense to define a field that is larger that its containing
type? This looks like it can introduce confusion or errors. It's already
not ideal that we can pass values that would be truncated; but this
makes it worse.
Anyway, if we decide to keep this, I think you want to remove the
+//! Note that the compiler will error out if the size of the setter's
arg exceeds the
+//! struct's storage size.
bit that was introduced in patch 2.
Powered by blists - more mailing lists