From: "Benno Lossin" <lossin@kernel.org>
To: "Jesung Yang" <y.j3ms.n@gmail.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
nouveau@lists.freedesktop.org
Subject: Re: [PATCH v4 1/4] rust: macros: add derive macro for `Into`
Date: Sat, 27 Dec 2025 23:25:27 +0100 [thread overview]
Message-ID: <DF9COCLM7VEQ.11RH8SIO59PMU@kernel.org> (raw)
In-Reply-To: <CA+tqQ4Kyy1re209kjBvtJU037MEcv+jQzEt=E9CMS4d2iuFR5g@mail.gmail.com>
On Sat Dec 27, 2025 at 11:45 AM CET, Jesung Yang wrote:
> On Sat, Dec 27, 2025 at 1:57 PM Benno Lossin <lossin@kernel.org> wrote:
>> On Fri Dec 26, 2025 at 10:36 AM CET, Jesung Yang wrote:
>> > On Fri, Dec 26, 2025 at 2:40 AM Benno Lossin <lossin@kernel.org> wrote:
>> >> On Thu Dec 25, 2025 at 9:37 AM CET, Jesung Yang via B4 Relay wrote:
>> >> > + fn emit_overflow_assert(
>> >> > + enum_ident: &Ident,
>> >> > + variants: &[Ident],
>> >> > + repr_ty: &syn::Path,
>> >> > + input_ty: &ValidTy,
>> >> > + ) -> TokenStream {
>> >>
>> >> I feel like we should track this via traits rather than using a const
>> >> assert. That approach will require & generate much less code.
>> >
>> > Sorry, but could you elaborate? A small example of what you have in
>> > mind would help a lot.
>>
>> Oh yeah sorry, I had something different in mind compared to what I'll
>> describe now, but it achieves the same thing without introducing new
>> traits:
>>
>> We have two options:
>> 1) We use `<input_ty as TryFrom<repr_ty>>::try_from` instead of writing
>> the `fits` function ourself.
>> 2) We require `input_ty: From<repr_ty>`.
>>
>> The first option would still check every variant and should behave the
>> same as your current code.
>>
>> Option 2 allows us to avoid the const altogether, but requires us to
>> choose the smallest integer as the representation (and if we want to be
>> able to use both `i8` and `u8`, we can't). I missed this before, so
>> using option 1 might be the only way to allow conversions of this kind.
>
> AFAIK, `<input_ty as TryFrom<repr_ty>>::try_from` cannot be called in
> const contexts without `#![feature(const_trait_impl, const_convert)]`.
> I assume we want to keep this validation at compile-time? If so, we
> might need to stick with the custom `fits` check for now. Please let me
> know if I misunderstood you.
Oh yeah that doesn't work (yet) :(
I'll take another look at the function itself then.
Cheers,
Benno
next prev parent reply other threads:[~2025-12-27 22:25 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-25 8:37 [PATCH v4 0/4] rust: add `TryFrom` and `Into` derive macros Jesung Yang via B4 Relay
2025-12-25 8:37 ` [PATCH v4 1/4] rust: macros: add derive macro for `Into` Jesung Yang via B4 Relay
2025-12-25 17:40 ` Benno Lossin
2025-12-26 9:36 ` Jesung Yang
2025-12-27 4:57 ` Benno Lossin
2025-12-27 10:45 ` Jesung Yang
2025-12-27 22:25 ` Benno Lossin [this message]
2025-12-29 12:29 ` Jesung Yang
2025-12-30 9:09 ` Benno Lossin
2026-01-21 3:20 ` Jesung Yang
2025-12-25 8:37 ` [PATCH v4 2/4] rust: macros: add derive macro for `TryFrom` Jesung Yang via B4 Relay
2025-12-25 17:42 ` Benno Lossin
2025-12-25 8:37 ` [PATCH v4 3/4] rust: macros: add private doctests for `Into` derive macro Jesung Yang via B4 Relay
2025-12-25 8:37 ` [PATCH v4 4/4] rust: macros: add private doctests for `TryFrom` " Jesung Yang via B4 Relay
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=DF9COCLM7VEQ.11RH8SIO59PMU@kernel.org \
--to=lossin@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=nouveau@lists.freedesktop.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=y.j3ms.n@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