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>
Subject: [PATCH v6 05/10] rust: macros: add private doctests for `TryFrom` derive macro
Date: Tue, 29 Sep 2026 21:58:50 +0800 [thread overview]
Message-ID: <20260929135855.36775-6-chaoji_xinren@163.com> (raw)
In-Reply-To: <20260929135855.36775-1-chaoji_xinren@163.com>
From: Jesung Yang <y.j3ms.n@gmail.com>
Add internal doctests to verify the `TryFrom` derive macro's logic. This
ensures comprehensive testing while keeping the public-facing
documentation compact and readable.
Signed-off-by: Jesung Yang <y.j3ms.n@gmail.com>
Signed-off-by: Kaiqi Guo <chaoji_xinren@163.com>
---
rust/macros/convert.rs | 578 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 578 insertions(+)
diff --git a/rust/macros/convert.rs b/rust/macros/convert.rs
index 31cdf84082e7..c07870914242 100644
--- a/rust/macros/convert.rs
+++ b/rust/macros/convert.rs
@@ -1024,3 +1024,581 @@ mod overflow_assert_works_on_unsigned_int {}
/// ```
mod any_into_target_overflow_is_rejected {}
}
+
+mod derive_try_from_tests {
+ /// ```
+ /// use kernel::{
+ /// macros::{
+ /// Into,
+ /// TryFrom, //
+ /// },
+ /// num::Bounded,
+ /// prelude::*, //
+ /// };
+ ///
+ /// #[derive(Debug, Into, PartialEq, TryFrom)]
+ /// #[convert(bool, Bounded<i8, 7>, Bounded<u8, 7>, i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize)]
+ /// enum Foo {
+ /// A,
+ /// B,
+ /// }
+ ///
+ /// assert_eq!(false, Foo::A.into());
+ /// assert_eq!(true, Foo::B.into());
+ /// assert_eq!(Ok(Foo::A), Foo::try_from(false));
+ /// assert_eq!(Ok(Foo::B), Foo::try_from(true));
+ ///
+ /// let foo_a: Bounded<i8, 7> = Foo::A.into();
+ /// let foo_b: Bounded<i8, 7> = Foo::B.into();
+ /// assert_eq!(Bounded::<i8, 7>::new::<0>(), foo_a);
+ /// assert_eq!(Bounded::<i8, 7>::new::<1>(), foo_b);
+ /// assert_eq!(Ok(Foo::A), Foo::try_from(Bounded::<i8, 7>::new::<0>()));
+ /// assert_eq!(Ok(Foo::B), Foo::try_from(Bounded::<i8, 7>::new::<1>()));
+ /// assert_eq!(Err(EINVAL), Foo::try_from(Bounded::<i8, 7>::new::<-1>()));
+ /// assert_eq!(Err(EINVAL), Foo::try_from(Bounded::<i8, 7>::new::<2>()));
+ ///
+ /// let foo_a: Bounded<u8, 7> = Foo::A.into();
+ /// let foo_b: Bounded<u8, 7> = Foo::B.into();
+ /// assert_eq!(Bounded::<u8, 7>::new::<0>(), foo_a);
+ /// assert_eq!(Bounded::<u8, 7>::new::<1>(), foo_b);
+ /// assert_eq!(Ok(Foo::A), Foo::try_from(Bounded::<u8, 7>::new::<0>()));
+ /// assert_eq!(Ok(Foo::B), Foo::try_from(Bounded::<u8, 7>::new::<1>()));
+ /// assert_eq!(Err(EINVAL), Foo::try_from(Bounded::<u8, 7>::new::<2>()));
+ ///
+ /// macro_rules! gen_signed_tests {
+ /// ($($type:ty),*) => {
+ /// $(
+ /// assert_eq!(0 as $type, Foo::A.into());
+ /// assert_eq!(1 as $type, Foo::B.into());
+ /// assert_eq!(Ok(Foo::A), Foo::try_from(0 as $type));
+ /// assert_eq!(Ok(Foo::B), Foo::try_from(1 as $type));
+ /// assert_eq!(Err(EINVAL), Foo::try_from((0 as $type) - 1));
+ /// assert_eq!(Err(EINVAL), Foo::try_from((1 as $type) + 1));
+ /// )*
+ /// };
+ /// }
+ /// macro_rules! gen_unsigned_tests {
+ /// ($($type:ty),*) => {
+ /// $(
+ /// assert_eq!(0 as $type, Foo::A.into());
+ /// assert_eq!(1 as $type, Foo::B.into());
+ /// assert_eq!(Ok(Foo::A), Foo::try_from(0 as $type));
+ /// assert_eq!(Ok(Foo::B), Foo::try_from(1 as $type));
+ /// assert_eq!(Err(EINVAL), Foo::try_from((1 as $type) + 1));
+ /// )*
+ /// };
+ /// }
+ /// gen_signed_tests!(i8, i16, i32, i64, i128, isize);
+ /// gen_unsigned_tests!(u8, u16, u32, u64, u128, usize);
+ /// ```
+ mod works_with_derive_into {}
+
+ /// ```
+ /// use kernel::{
+ /// macros::TryFrom,
+ /// prelude::*, //
+ /// };
+ ///
+ /// #[derive(Debug, PartialEq, TryFrom)]
+ /// #[try_from(u8)]
+ /// enum Foo {
+ /// // Works with const expressions.
+ /// A = add(0, 0),
+ /// B = 2_isize.pow(1) - 1,
+ /// }
+ ///
+ /// const fn add(a: isize, b: isize) -> isize {
+ /// a + b
+ /// }
+ ///
+ /// assert_eq!(Ok(Foo::A), Foo::try_from(0_u8));
+ /// assert_eq!(Ok(Foo::B), Foo::try_from(1_u8));
+ /// assert_eq!(Err(EINVAL), Foo::try_from(2_u8));
+ /// ```
+ mod works_with_const_expr {}
+
+ /// ```
+ /// use kernel::{
+ /// macros::TryFrom,
+ /// prelude::*, //
+ /// };
+ ///
+ /// #[derive(Debug, PartialEq, TryFrom)]
+ /// #[try_from(bool)]
+ /// enum Foo {
+ /// A,
+ /// B,
+ /// }
+ ///
+ /// assert_eq!(Ok(Foo::A), Foo::try_from(false));
+ /// assert_eq!(Ok(Foo::B), Foo::try_from(true));
+ ///
+ /// #[derive(Debug, PartialEq, TryFrom)]
+ /// #[try_from(bool)]
+ /// enum Bar {
+ /// A,
+ /// }
+ ///
+ /// assert_eq!(Ok(Bar::A), Bar::try_from(false));
+ /// assert_eq!(Err(EINVAL), Bar::try_from(true));
+ ///
+ /// #[derive(Debug, PartialEq, TryFrom)]
+ /// #[try_from(bool)]
+ /// enum Baz {
+ /// A = 1,
+ /// }
+ ///
+ /// assert_eq!(Err(EINVAL), Baz::try_from(false));
+ /// assert_eq!(Ok(Baz::A), Baz::try_from(true));
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(bool)]
+ /// enum Foo {
+ /// // `-1` cannot be represented with `bool`.
+ /// A = -1,
+ /// }
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(bool)]
+ /// enum Foo {
+ /// // `2` cannot be represented with `bool`.
+ /// A = 2,
+ /// }
+ /// ```
+ mod overflow_assert_works_on_bool {}
+
+ /// ```
+ /// use kernel::{
+ /// macros::TryFrom,
+ /// num::Bounded,
+ /// prelude::*, //
+ /// };
+ ///
+ /// #[derive(Debug, PartialEq, TryFrom)]
+ /// #[try_from(Bounded<i8, 7>)]
+ /// enum Foo {
+ /// A = -1 << 6, // The minimum value of `Bounded<i8, 7>`.
+ /// B = (1 << 6) - 1, // The maximum value of `Bounded<i8, 7>`.
+ /// }
+ ///
+ /// assert_eq!(Ok(Foo::A), Foo::try_from(Bounded::<i8, 7>::new::<{ -1_i8 << 6 }>()));
+ /// assert_eq!(Ok(Foo::B), Foo::try_from(Bounded::<i8, 7>::new::<{ (1_i8 << 6) - 1 }>()));
+ /// assert_eq!(Err(EINVAL), Foo::try_from(Bounded::<i8, 7>::new::<{ (-1_i8 << 6) + 1 }>()));
+ /// assert_eq!(Err(EINVAL), Foo::try_from(Bounded::<i8, 7>::new::<{ (1_i8 << 6) - 2 }>()));
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(Bounded<i8, 7>)]
+ /// enum Foo {
+ /// // `1 << 6` cannot be represented with `Bounded<i8, 7>`.
+ /// A = 1 << 6,
+ /// }
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(Bounded<i8, 7>)]
+ /// enum Foo {
+ /// // `(-1 << 6) - 1` cannot be represented with `Bounded<i8, 7>`.
+ /// A = (-1 << 6) - 1,
+ /// }
+ /// ```
+ ///
+ /// ```
+ /// use kernel::{
+ /// macros::TryFrom,
+ /// num::Bounded,
+ /// prelude::*, //
+ /// };
+ ///
+ /// #[derive(Debug, PartialEq, TryFrom)]
+ /// #[try_from(Bounded<i8, 1>)]
+ /// enum Foo {
+ /// A = -1, // The minimum value of `Bounded<i8, 1>`.
+ /// B, // The maximum value of `Bounded<i8, 1>`.
+ /// }
+ ///
+ /// assert_eq!(Ok(Foo::A), Foo::try_from(Bounded::<i8, 1>::new::<{ -1_i8 }>()));
+ /// assert_eq!(Ok(Foo::B), Foo::try_from(Bounded::<i8, 1>::new::<{ 0_i8 } >()));
+ ///
+ /// #[derive(Debug, PartialEq, TryFrom)]
+ /// #[try_from(Bounded<i8, 1>)]
+ /// enum Bar {
+ /// A = -1, // The minimum value of `Bounded<i8, 1>`.
+ /// }
+ ///
+ /// assert_eq!(Ok(Bar::A), Bar::try_from(Bounded::<i8, 1>::new::<{ -1_i8 }>()));
+ /// assert_eq!(Err(EINVAL), Bar::try_from(Bounded::<i8, 1>::new::<{ 0_i8 } >()));
+ ///
+ /// #[derive(Debug, PartialEq, TryFrom)]
+ /// #[try_from(Bounded<i8, 1>)]
+ /// enum Baz {
+ /// A, // The maximum value of `Bounded<i8, 1>`.
+ /// }
+ ///
+ /// assert_eq!(Err(EINVAL), Baz::try_from(Bounded::<i8, 1>::new::<{ -1_i8 }>()));
+ /// assert_eq!(Ok(Baz::A), Baz::try_from(Bounded::<i8, 1>::new::<{ 0_i8 } >()));
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(Bounded<i8, 1>)]
+ /// enum Foo {
+ /// // `1` cannot be represented with `Bounded<i8, 1>`.
+ /// A = 1,
+ /// }
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(Bounded<i8, 1>)]
+ /// enum Foo {
+ /// // `-2` cannot be represented with `Bounded<i8, 1>`.
+ /// A = -2,
+ /// }
+ /// ```
+ ///
+ /// ```
+ /// use kernel::{
+ /// macros::TryFrom,
+ /// num::Bounded,
+ /// prelude::*, //
+ /// };
+ ///
+ /// #[derive(Debug, PartialEq, TryFrom)]
+ /// #[try_from(Bounded<i32, 32>)]
+ /// #[repr(i64)]
+ /// enum Foo {
+ /// A = i32::MIN as i64,
+ /// B = i32::MAX as i64,
+ /// }
+ ///
+ /// assert_eq!(Ok(Foo::A), Foo::try_from(Bounded::<i32, 32>::new::<{ i32::MIN }>()));
+ /// assert_eq!(Ok(Foo::B), Foo::try_from(Bounded::<i32, 32>::new::<{ i32::MAX }>()));
+ /// assert_eq!(Err(EINVAL), Foo::try_from(Bounded::<i32, 32>::new::<{ i32::MIN + 1 }>()));
+ /// assert_eq!(Err(EINVAL), Foo::try_from(Bounded::<i32, 32>::new::<{ i32::MAX - 1 }>()));
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(Bounded<i32, 32>)]
+ /// #[repr(i64)]
+ /// enum Foo {
+ /// // `1 << 31` cannot be represented with `Bounded<i32, 32>`.
+ /// A = 1 << 31,
+ /// }
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(Bounded<i32, 32>)]
+ /// #[repr(i64)]
+ /// enum Foo {
+ /// // `(-1 << 31) - 1` cannot be represented with `Bounded<i32, 32>`.
+ /// A = (-1 << 31) - 1,
+ /// }
+ /// ```
+ mod overflow_assert_works_on_signed_bounded {}
+
+ /// ```
+ /// use kernel::{
+ /// macros::TryFrom,
+ /// num::Bounded,
+ /// prelude::*, //
+ /// };
+ ///
+ /// #[derive(Debug, PartialEq, TryFrom)]
+ /// #[try_from(Bounded<u8, 7>)]
+ /// enum Foo {
+ /// A, // The minimum value of `Bounded<u8, 7>`.
+ /// B = (1 << 7) - 1, // The maximum value of `Bounded<u8, 7>`.
+ /// }
+ ///
+ /// assert_eq!(Ok(Foo::A), Foo::try_from(Bounded::<u8, 7>::new::<{ 0 }>()));
+ /// assert_eq!(Ok(Foo::B), Foo::try_from(Bounded::<u8, 7>::new::<{ (1_u8 << 7) - 1 }>()));
+ /// assert_eq!(Err(EINVAL), Foo::try_from(Bounded::<u8, 7>::new::<{ 1 }>()));
+ /// assert_eq!(Err(EINVAL), Foo::try_from(Bounded::<u8, 7>::new::<{ (1_u8 << 7) - 2 }>()));
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(Bounded<u8, 7>)]
+ /// enum Foo {
+ /// // `1 << 7` cannot be represented with `Bounded<u8, 7>`.
+ /// A = 1 << 7,
+ /// }
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(Bounded<u8, 7>)]
+ /// enum Foo {
+ /// // `-1` cannot be represented with `Bounded<u8, 7>`.
+ /// A = -1,
+ /// }
+ /// ```
+ ///
+ /// ```
+ /// use kernel::{
+ /// macros::TryFrom,
+ /// num::Bounded,
+ /// prelude::*, //
+ /// };
+ ///
+ /// #[derive(Debug, PartialEq, TryFrom)]
+ /// #[try_from(Bounded<u8, 1>)]
+ /// enum Foo {
+ /// A, // The minimum value of `Bounded<u8, 1>`.
+ /// B, // The maximum value of `Bounded<u8, 1>`.
+ /// }
+ ///
+ /// assert_eq!(Ok(Foo::A), Foo::try_from(Bounded::<u8, 1>::new::<{ 0 }>()));
+ /// assert_eq!(Ok(Foo::B), Foo::try_from(Bounded::<u8, 1>::new::<{ 1 }>()));
+ ///
+ /// #[derive(Debug, PartialEq, TryFrom)]
+ /// #[try_from(Bounded<u8, 1>)]
+ /// enum Bar {
+ /// A, // The minimum value of `Bounded<u8, 1>`.
+ /// }
+ ///
+ /// assert_eq!(Ok(Bar::A), Bar::try_from(Bounded::<u8, 1>::new::<{ 0 }>()));
+ /// assert_eq!(Err(EINVAL), Bar::try_from(Bounded::<u8, 1>::new::<{ 1 }>()));
+ ///
+ /// #[derive(Debug, PartialEq, TryFrom)]
+ /// #[try_from(Bounded<u8, 1>)]
+ /// enum Baz {
+ /// A = 1, // The maximum value of `Bounded<u8, 1>`.
+ /// }
+ ///
+ /// assert_eq!(Err(EINVAL), Baz::try_from(Bounded::<u8, 1>::new::<{ 0 }>()));
+ /// assert_eq!(Ok(Baz::A), Baz::try_from(Bounded::<u8, 1>::new::<{ 1 }>()));
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(Bounded<u8, 1>)]
+ /// enum Foo {
+ /// // `2` cannot be represented with `Bounded<u8, 1>`.
+ /// A = 2,
+ /// }
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(Bounded<u8, 1>)]
+ /// enum Foo {
+ /// // `-1` cannot be represented with `Bounded<u8, 1>`.
+ /// A = -1,
+ /// }
+ /// ```
+ ///
+ /// ```
+ /// use kernel::{
+ /// macros::TryFrom,
+ /// num::Bounded,
+ /// prelude::*, //
+ /// };
+ ///
+ /// #[derive(Debug, PartialEq, TryFrom)]
+ /// #[try_from(Bounded<u32, 32>)]
+ /// #[repr(u64)]
+ /// enum Foo {
+ /// A = u32::MIN as u64,
+ /// B = u32::MAX as u64,
+ /// }
+ ///
+ /// assert_eq!(Ok(Foo::A), Foo::try_from(Bounded::<u32, 32>::new::<{ u32::MIN }>()));
+ /// assert_eq!(Ok(Foo::B), Foo::try_from(Bounded::<u32, 32>::new::<{ u32::MAX }>()));
+ /// assert_eq!(Err(EINVAL), Foo::try_from(Bounded::<u32, 32>::new::<{ u32::MIN + 1 }>()));
+ /// assert_eq!(Err(EINVAL), Foo::try_from(Bounded::<u32, 32>::new::<{ u32::MAX - 1 }>()));
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(Bounded<u32, 32>)]
+ /// #[repr(u64)]
+ /// enum Foo {
+ /// // `1 << 32` cannot be represented with `Bounded<u32, 32>`.
+ /// A = 1 << 32,
+ /// }
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(Bounded<u32, 32>)]
+ /// #[repr(u64)]
+ /// enum Foo {
+ /// // `-1` cannot be represented with `Bounded<u32, 32>`.
+ /// A = -1,
+ /// }
+ /// ```
+ mod overflow_assert_works_on_unsigned_bounded {}
+
+ /// ```
+ /// use kernel::{
+ /// macros::TryFrom,
+ /// num::Bounded,
+ /// prelude::*, //
+ /// };
+ ///
+ /// #[derive(Debug, PartialEq, TryFrom)]
+ /// #[try_from(isize)]
+ /// #[repr(isize)]
+ /// enum Foo {
+ /// A = isize::MIN,
+ /// B = isize::MAX,
+ /// }
+ ///
+ /// assert_eq!(Ok(Foo::A), Foo::try_from(isize::MIN));
+ /// assert_eq!(Ok(Foo::B), Foo::try_from(isize::MAX));
+ /// assert_eq!(Err(EINVAL), Foo::try_from(isize::MIN + 1));
+ /// assert_eq!(Err(EINVAL), Foo::try_from(isize::MAX - 1));
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(isize)]
+ /// #[repr(usize)]
+ /// enum Foo {
+ /// A = (isize::MAX as usize) + 1
+ /// }
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(i32)]
+ /// #[repr(i64)]
+ /// enum Foo {
+ /// A = (i32::MIN as i64) - 1,
+ /// }
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(i32)]
+ /// #[repr(i64)]
+ /// enum Foo {
+ /// A = (i32::MAX as i64) + 1,
+ /// }
+ /// ```
+ mod overflow_assert_works_on_signed_int {}
+
+ /// ```
+ /// use kernel::{
+ /// macros::TryFrom,
+ /// num::Bounded,
+ /// prelude::*, //
+ /// };
+ ///
+ /// #[derive(Debug, PartialEq, TryFrom)]
+ /// #[try_from(usize)]
+ /// #[repr(usize)]
+ /// enum Foo {
+ /// A = usize::MIN,
+ /// B = usize::MAX,
+ /// }
+ ///
+ /// assert_eq!(Ok(Foo::A), Foo::try_from(usize::MIN));
+ /// assert_eq!(Ok(Foo::B), Foo::try_from(usize::MAX));
+ /// assert_eq!(Err(EINVAL), Foo::try_from(usize::MIN + 1));
+ /// assert_eq!(Err(EINVAL), Foo::try_from(usize::MAX - 1));
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(usize)]
+ /// #[repr(isize)]
+ /// enum Foo {
+ /// A = -1,
+ /// }
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(u32)]
+ /// #[repr(i64)]
+ /// enum Foo {
+ /// A = (u32::MIN as i64) - 1,
+ /// }
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(u32)]
+ /// #[repr(i64)]
+ /// enum Foo {
+ /// A = (u32::MAX as i64) + 1,
+ /// }
+ /// ```
+ mod overflow_assert_works_on_unsigned_int {}
+
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(Bounded<i8, 7>, i8, i16, i32, i64)]
+ /// #[repr(i8)]
+ /// enum Foo {
+ /// // `i8::MAX` cannot be represented with `Bounded<i8, 7>`.
+ /// A = i8::MAX,
+ /// }
+ /// ```
+ ///
+ /// ```compile_fail
+ /// use kernel::macros::TryFrom;
+ ///
+ /// #[derive(TryFrom)]
+ /// #[try_from(i8, i16, i32, i64, Bounded<i8, 7>)]
+ /// #[repr(i8)]
+ /// enum Foo {
+ /// // `i8::MAX` cannot be represented with `Bounded<i8, 7>`.
+ /// A = i8::MAX,
+ /// }
+ /// ```
+ mod any_try_from_target_overflow_is_rejected {}
+}
next prev parent reply other threads:[~2026-09-29 13:59 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 ` Kaiqi Guo [this message]
2026-09-29 13:58 ` [PATCH v6 06/10] rust: macros: exercise the intended conversion doctest failures Kaiqi Guo
2026-09-29 18:47 ` 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-6-chaoji_xinren@163.com \
--to=chaoji_xinren@163.com \
--cc=acourbot@nvidia.com \
--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