From: Kaiqi Guo <chaoji_xinren@163.com>
To: rust-for-linux@vger.kernel.org, Miguel Ojeda <ojeda@kernel.org>
Cc: Jesung Yang <y.j3ms.n@gmail.com>,
Alexandre Courbot <acourbot@nvidia.com>,
Danilo Krummrich <dakr@kernel.org>,
nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, Kaiqi Guo <chaoji_xinren@163.com>,
Charalampos Mitrodimas <charmitro@posteo.net>
Subject: [PATCH v6 06/10] rust: macros: exercise the intended conversion doctest failures
Date: Tue, 29 Sep 2026 21:58:51 +0800 [thread overview]
Message-ID: <20260929135855.36775-7-chaoji_xinren@163.com> (raw)
In-Reply-To: <20260929135855.36775-1-chaoji_xinren@163.com>
Use unit-only enums in the repr(C) compile-fail examples so they
exercise the representation check rather than rejecting a struct. Fix
the missing semicolon incidentally hidden by the TryFrom negative test,
and correct the convert helper documentation.
Give the negative Bounded<u32, 32> examples a signed enum representation
so that -1 is a valid discriminant and the conversion overflow assertion
is what rejects it.
Suggested-by: Charalampos Mitrodimas <charmitro@posteo.net>
Link: https://lore.kernel.org/rust-for-linux/m2qzr81jrd.fsf@ip-192-168-1-196.ap-southeast-1.compute.internal/
Signed-off-by: Kaiqi Guo <chaoji_xinren@163.com>
---
rust/macros/convert.rs | 4 ++--
rust/macros/lib.rs | 12 +++++++++---
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/rust/macros/convert.rs b/rust/macros/convert.rs
index c07870914242..78efbc7b99d7 100644
--- a/rust/macros/convert.rs
+++ b/rust/macros/convert.rs
@@ -893,7 +893,7 @@ mod overflow_assert_works_on_signed_bounded {}
///
/// #[derive(Into)]
/// #[into(Bounded<u32, 32>)]
- /// #[repr(u64)]
+ /// #[repr(i64)]
/// enum Foo {
/// // `-1` cannot be represented with `Bounded<u32, 32>`.
/// A = -1,
@@ -1459,7 +1459,7 @@ mod overflow_assert_works_on_signed_bounded {}
///
/// #[derive(TryFrom)]
/// #[try_from(Bounded<u32, 32>)]
- /// #[repr(u64)]
+ /// #[repr(i64)]
/// enum Foo {
/// // `-1` cannot be represented with `Bounded<u32, 32>`.
/// A = -1,
diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs
index cc6a96516c93..4d420d34ed6b 100644
--- a/rust/macros/lib.rs
+++ b/rust/macros/lib.rs
@@ -656,7 +656,7 @@ pub fn CovariantForLt(input: TokenStream) -> TokenStream {
///
/// ## With `#[convert(...)]`
///
-/// The macro implements `From<Foo>` for each `T` specified in `#[into(...)]`,
+/// The macro implements `From<Foo>` for each `T` specified in `#[convert(...)]`,
/// which always overrides `#[repr(...)]`. `#[convert(...)]` is useful when the same type
/// needs to be specified in both `#[into(...)]` and `#[try_from(...)]`:
///
@@ -734,7 +734,10 @@ pub fn CovariantForLt(input: TokenStream) -> TokenStream {
/// // `repr(C)` enums are not allowed.
/// #[derive(Into)]
/// #[repr(C)]
-/// struct Foo(u8);
+/// enum Foo {
+/// A,
+/// B,
+/// }
/// ```
#[proc_macro_derive(Into, attributes(into, convert))]
pub fn derive_into(input: TokenStream) -> TokenStream {
@@ -947,7 +950,10 @@ pub fn derive_into(input: TokenStream) -> TokenStream {
/// // `repr(C)` enums are not allowed.
/// #[derive(TryFrom)]
/// #[repr(C)]
-/// struct Foo(u8)
+/// enum Foo {
+/// A,
+/// B,
+/// }
/// ```
#[proc_macro_derive(TryFrom, attributes(try_from, convert))]
pub fn derive_try_from(input: TokenStream) -> TokenStream {
next prev parent reply other threads:[~2026-09-29 14:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 13:58 [PATCH v6 00/10] rust: add conversion derives and exhaustive From support Kaiqi Guo
2026-09-29 13:58 ` [PATCH v6 01/10] rust: macros: add derive macro for `Into` Kaiqi Guo
2026-09-29 13:58 ` [PATCH v6 02/10] rust: macros: add derive macro for `TryFrom` Kaiqi Guo
2026-09-29 13:58 ` [PATCH v6 03/10] rust: macros: add `convert` helper attribute Kaiqi Guo
2026-09-29 13:58 ` [PATCH v6 04/10] rust: macros: add private doctests for `Into` derive macro Kaiqi Guo
2026-09-29 13:58 ` [PATCH v6 05/10] rust: macros: add private doctests for `TryFrom` " Kaiqi Guo
2026-09-29 13:58 ` Kaiqi Guo [this message]
2026-09-29 18:47 ` [PATCH v6 06/10] rust: macros: exercise the intended conversion doctest failures Miguel Ojeda
2026-09-29 13:58 ` [PATCH v6 07/10] rust: macros: derive From for exhaustive enum conversions Kaiqi Guo
2026-09-29 13:58 ` [PATCH v6 08/10] rust: macros: test exhaustive conversion derives Kaiqi Guo
2026-09-29 13:58 ` [PATCH v6 09/10] rust: macros: validate and qualify conversion helper types Kaiqi Guo
2026-09-29 13:58 ` [PATCH v6 10/10] gpu: nova-core: use conversion derives for two register enums Kaiqi Guo
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=20260929135855.36775-7-chaoji_xinren@163.com \
--to=chaoji_xinren@163.com \
--cc=acourbot@nvidia.com \
--cc=charmitro@posteo.net \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--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