From: "Benno Lossin" <lossin@kernel.org>
To: y.j3ms.n@gmail.com, "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>
Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
nouveau@lists.freedesktop.org
Subject: Re: [PATCH v4 2/4] rust: macros: add derive macro for `TryFrom`
Date: Thu, 25 Dec 2025 18:42:31 +0100 [thread overview]
Message-ID: <DF7HEMI7I3LS.FW1IPV2QS2HB@kernel.org> (raw)
In-Reply-To: <20251225-try-from-into-macro-v4-2-4a563d597836@gmail.com>
On Thu Dec 25, 2025 at 9:37 AM CET, Jesung Yang via B4 Relay wrote:
> +/// ## Compile-time Overflow Assertion
> +///
> +/// The following examples do not compile:
> +///
> +/// ```compile_fail
> +/// # use kernel::macros::Into;
> +/// #[derive(Into)]
> +/// #[into(u8)]
> +/// enum Foo {
> +/// // `256` is larger than `u8::MAX`.
> +/// A = 256,
> +/// }
> +/// ```
> +///
> +/// ```compile_fail
> +/// # use kernel::macros::Into;
> +/// #[derive(Into)]
> +/// #[into(u8)]
> +/// enum Foo {
> +/// // `-1` cannot be represented with `u8`.
> +/// A = -1,
> +/// }
> +/// ```
These two are copy-pasted from the `into` macro.
Cheers,
Benno
> +///
> +/// ## Unsupported Cases
> +///
> +/// The following examples do not compile:
> +///
> +/// ```compile_fail
> +/// # use kernel::macros::TryFrom;
> +/// // Tuple-like enums or struct-like enums are not allowed.
> +/// #[derive(TryFrom)]
> +/// enum Foo {
> +/// A(u8),
> +/// B { inner: u8 },
> +/// }
> +/// ```
> +///
> +/// ```compile_fail
> +/// # use kernel::macros::TryFrom;
> +/// // Structs are not allowed.
> +/// #[derive(TryFrom)]
> +/// struct Foo(u8);
> +/// ```
> +#[proc_macro_derive(TryFrom, attributes(try_from))]
> +pub fn derive_try_from(input: TokenStream) -> TokenStream {
> + let input = parse_macro_input!(input as DeriveInput);
> + convert::derive_try_from(input)
> + .unwrap_or_else(syn::Error::into_compile_error)
> + .into()
> +}
WARNING: multiple messages have this Message-ID (diff)
From: "Benno Lossin" <lossin@kernel.org>
To: y.j3ms.n@gmail.com, "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>
Cc: <linux-kernel@vger.kernel.org>, <rust-for-linux@vger.kernel.org>,
<nouveau@lists.freedesktop.org>
Subject: Re: [PATCH v4 2/4] rust: macros: add derive macro for `TryFrom`
Date: Thu, 25 Dec 2025 18:42:31 +0100 [thread overview]
Message-ID: <DF7HEMI7I3LS.FW1IPV2QS2HB@kernel.org> (raw)
In-Reply-To: <20251225-try-from-into-macro-v4-2-4a563d597836@gmail.com>
On Thu Dec 25, 2025 at 9:37 AM CET, Jesung Yang via B4 Relay wrote:
> +/// ## Compile-time Overflow Assertion
> +///
> +/// The following examples do not compile:
> +///
> +/// ```compile_fail
> +/// # use kernel::macros::Into;
> +/// #[derive(Into)]
> +/// #[into(u8)]
> +/// enum Foo {
> +/// // `256` is larger than `u8::MAX`.
> +/// A = 256,
> +/// }
> +/// ```
> +///
> +/// ```compile_fail
> +/// # use kernel::macros::Into;
> +/// #[derive(Into)]
> +/// #[into(u8)]
> +/// enum Foo {
> +/// // `-1` cannot be represented with `u8`.
> +/// A = -1,
> +/// }
> +/// ```
These two are copy-pasted from the `into` macro.
Cheers,
Benno
> +///
> +/// ## Unsupported Cases
> +///
> +/// The following examples do not compile:
> +///
> +/// ```compile_fail
> +/// # use kernel::macros::TryFrom;
> +/// // Tuple-like enums or struct-like enums are not allowed.
> +/// #[derive(TryFrom)]
> +/// enum Foo {
> +/// A(u8),
> +/// B { inner: u8 },
> +/// }
> +/// ```
> +///
> +/// ```compile_fail
> +/// # use kernel::macros::TryFrom;
> +/// // Structs are not allowed.
> +/// #[derive(TryFrom)]
> +/// struct Foo(u8);
> +/// ```
> +#[proc_macro_derive(TryFrom, attributes(try_from))]
> +pub fn derive_try_from(input: TokenStream) -> TokenStream {
> + let input = parse_macro_input!(input as DeriveInput);
> + convert::derive_try_from(input)
> + .unwrap_or_else(syn::Error::into_compile_error)
> + .into()
> +}
next prev parent reply other threads:[~2025-12-25 17:42 UTC|newest]
Thread overview: 21+ 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
2025-12-25 8:37 ` Jesung Yang via B4 Relay
2025-12-25 8:37 ` [PATCH v4 1/4] rust: macros: add derive macro for `Into` Jesung Yang
2025-12-25 8:37 ` Jesung Yang via B4 Relay
2025-12-25 17:40 ` Benno Lossin
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
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
2025-12-25 8:37 ` Jesung Yang via B4 Relay
2025-12-25 17:42 ` Benno Lossin [this message]
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
2025-12-25 8:37 ` Jesung Yang via B4 Relay
2025-12-25 8:37 ` [PATCH v4 4/4] rust: macros: add private doctests for `TryFrom` " Jesung Yang
2025-12-25 8:37 ` 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=DF7HEMI7I3LS.FW1IPV2QS2HB@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 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.