[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAJ-ks9=1BOsd-edBH-ZsDLzhtX=YfvZPMHebX=br4Wc1K1V-TA@mail.gmail.com>
Date: Tue, 25 Mar 2025 06:45:40 -0400
From: Tamir Duberstein <tamird@...il.com>
To: Benno Lossin <benno.lossin@...ton.me>
Cc: Masahiro Yamada <masahiroy@...nel.org>, Nathan Chancellor <nathan@...nel.org>,
Nicolas Schier <nicolas@...sle.eu>, Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>, Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Andreas Hindborg <a.hindborg@...nel.org>, Alice Ryhl <aliceryhl@...gle.com>,
Trevor Gross <tmgross@...ch.edu>, Danilo Krummrich <dakr@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>, "Rafael J. Wysocki" <rafael@...nel.org>,
Brendan Higgins <brendan.higgins@...ux.dev>, David Gow <davidgow@...gle.com>,
Rae Moar <rmoar@...gle.com>, Bjorn Helgaas <bhelgaas@...gle.com>,
Luis Chamberlain <mcgrof@...nel.org>, Russ Weight <russ.weight@...ux.dev>, Rob Herring <robh@...nel.org>,
Saravana Kannan <saravanak@...gle.com>, Abdiel Janulgue <abdiel.janulgue@...il.com>,
Daniel Almeida <daniel.almeida@...labora.com>, Robin Murphy <robin.murphy@....com>,
Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>, Maxime Ripard <mripard@...nel.org>,
Thomas Zimmermann <tzimmermann@...e.de>, David Airlie <airlied@...il.com>, Simona Vetter <simona@...ll.ch>,
FUJITA Tomonori <fujita.tomonori@...il.com>, linux-kbuild@...r.kernel.org,
linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org,
linux-kselftest@...r.kernel.org, kunit-dev@...glegroups.com,
linux-pci@...r.kernel.org, linux-block@...r.kernel.org,
devicetree@...r.kernel.org, dri-devel@...ts.freedesktop.org,
netdev@...r.kernel.org
Subject: Re: [PATCH v6 6/6] rust: enable `clippy::cast_lossless` lint
On Tue, Mar 25, 2025 at 6:40 AM Benno Lossin <benno.lossin@...ton.me> wrote:
>
> On Mon Mar 24, 2025 at 11:01 PM CET, Tamir Duberstein wrote:
> > Before Rust 1.29.0, Clippy introduced the `cast_lossless` lint [1]:
> >
> >> Rust’s `as` keyword will perform many kinds of conversions, including
> >> silently lossy conversions. Conversion functions such as `i32::from`
> >> will only perform lossless conversions. Using the conversion functions
> >> prevents conversions from becoming silently lossy if the input types
> >> ever change, and makes it clear for people reading the code that the
> >> conversion is lossless.
> >
> > While this doesn't eliminate unchecked `as` conversions, it makes such
> > conversions easier to scrutinize. It also has the slight benefit of
> > removing a degree of freedom on which to bikeshed. Thus apply the
> > changes and enable the lint -- no functional change intended.
> >
> > Link: https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless [1]
> > Suggested-by: Benno Lossin <benno.lossin@...ton.me>
> > Link: https://lore.kernel.org/all/D8ORTXSUTKGL.1KOJAGBM8F8TN@proton.me/
> > Signed-off-by: Tamir Duberstein <tamird@...il.com>
>
> One nit below, but you may add:
>
> Reviewed-by: Benno Lossin <benno.lossin@...ton.me>
Thanks!
>
> > ---
> > Makefile | 1 +
> > drivers/gpu/drm/drm_panic_qr.rs | 10 +++++-----
> > rust/bindings/lib.rs | 2 +-
> > rust/kernel/net/phy.rs | 4 ++--
> > 4 files changed, 9 insertions(+), 8 deletions(-)
>
> > diff --git a/rust/bindings/lib.rs b/rust/bindings/lib.rs
> > index 0486a32ed314..591e4ca9bc54 100644
> > --- a/rust/bindings/lib.rs
> > +++ b/rust/bindings/lib.rs
> > @@ -25,7 +25,7 @@
> > )]
> >
> > #[allow(dead_code)]
> > -#[allow(clippy::ptr_as_ptr)]
> > +#[allow(clippy::cast_lossless, clippy::ptr_as_ptr)]
>
> Not sure if we instead want this in a separate attribute, ultimately it
> doesn't really matter, but why should `undocumented_unsafe_blocks` be
> special?
No reason. Moved it to a separate line. I won't respin just for this -
hopefully Miguel doesn't mind fixing when he takes it, if there's not
a v7 by then.
Tamir
Powered by blists - more mailing lists