[PATCH v6 06/10] rust: macros: exercise the intended conversion doctest failures

From: Kaiqi Guo

Date: Tue Sep 29 2026 - 10:08:16 EST


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@xxxxxxxxxx>

Link: https://lore.kernel.org/rust-for-linux/m2qzr81jrd.fsf@xxxxxxxxxxxxxxxxxxx-southeast-1.compute.internal/
Signed-off-by: Kaiqi Guo <chaoji_xinren@xxxxxxx>
---
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 {