dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kaiqi Guo" <chaoji_xinren@163.com>
Cc: "Danilo Krummrich" <dakr@kernel.org>,
	gary@garyguo.net, dri-devel@lists.freedesktop.org,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	ojeda@kernel.org
Subject: Re: [PATCH v6 02/10] rust: macros: add derive macro for `TryFrom`
Date: Tue, 29 Sep 2026 14:10:18 +0000	[thread overview]
Message-ID: <20260929141019.1F1351F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260929135855.36775-3-chaoji_xinren@163.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] rust: macros: unused_comparisons warning on 128-bit boundary checks
- [Low] rust: macros: dead_code and unused_variables on empty enums
--

commit 2f4a5e53f9efd805dce115afdbd130dde8b72a62
Author: Jesung Yang <y.j3ms.n@gmail.com>

rust: macros: add derive macro for `TryFrom`

Introduce a procedural macro TryFrom to automatically implement the TryFrom
trait for unit-only enums, reducing boilerplate when interpreting numeric
values as enum variants.

> diff --git a/rust/macros/convert.rs b/rust/macros/convert.rs
> index 6702c2e48c1fe..c64e35447859c 100644
> --- a/rust/macros/convert.rs
> +++ b/rust/macros/convert.rs

[ ... ]

> @@ -245,6 +253,56 @@ fn from(#param: #enum_ident) -> #input_ty {
>          }
>      }
>  
> +    fn impl_try_from(
> +        enum_ident: &Ident,
> +        variants: &[Ident],
> +        repr_ty: &syn::Path,
> +        input_ty: &ValidTy,
> +    ) -> TokenStream {
> +        let param = Ident::new("value", Span::call_site());

[Severity: Low]
Does this trigger an unused_variables warning if the user derives TryFrom on a
variant-less (empty) enum?

The generated try_from function never uses the value parameter in that case,
which could result in a build failure under CONFIG_WERROR.

> +
> +        let overflow_assertion = emit_overflow_assert(enum_ident, variants, repr_ty, input_ty);

[Severity: Low]
Can this generated overflow assertion cause a dead_code warning for empty enums?

When an enum is empty, no variant assertions are generated to invoke the
internal fits() helper function, leaving it unused.

Also, when deriving TryFrom for a 128-bit target type, does the generated
fits() function trigger the unused_comparisons lint?

For example, the bounds checks in emit_overflow_assert() generate comparisons
like this:

    (d as ::core::primitive::u128) <= (dst_max as ::core::primitive::u128)

If dst_max is the maximum possible value for a u128, the comparison is
trivially true and triggers the unused_comparisons lint. This can cause build
failures under CONFIG_WERROR.

Would it make sense to apply #[allow(unused_comparisons)] to the entire fits()
function scope rather than just the signedness boolean variables?

> +        let emit_cast = |variant| {
> +            let qualified_variant = ::quote::quote! { #enum_ident::#variant };
> +            match input_ty {

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260929135855.36775-1-chaoji_xinren@163.com?part=2

  parent reply	other threads:[~2026-09-29 14:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260929135855.36775-1-chaoji_xinren@163.com>
2026-09-29 13:58 ` [PATCH v6 10/10] gpu: nova-core: use conversion derives for two register enums Kaiqi Guo
     [not found] ` <20260929135855.36775-9-chaoji_xinren@163.com>
2026-09-29 14:07   ` [PATCH v6 08/10] rust: macros: test exhaustive conversion derives sashiko-bot
     [not found] ` <20260929135855.36775-3-chaoji_xinren@163.com>
2026-09-29 14:10   ` sashiko-bot [this message]
     [not found] ` <20260929135855.36775-2-chaoji_xinren@163.com>
2026-09-29 14:10   ` [PATCH v6 01/10] rust: macros: add derive macro for `Into` sashiko-bot
     [not found] ` <20260929135855.36775-7-chaoji_xinren@163.com>
2026-09-29 18:47   ` [PATCH v6 06/10] rust: macros: exercise the intended conversion doctest failures Miguel Ojeda

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=20260929141019.1F1351F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=chaoji_xinren@163.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=ojeda@kernel.org \
    --cc=sashiko-reviews@lists.linux.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox