* [PATCH] rust: num: remove narrowing `uX_into_uY` functions
@ 2026-11-30 14:18 Gary Guo
2026-11-30 14:21 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Gary Guo @ 2026-11-30 14:18 UTC (permalink / raw)
To: Alexandre Courbot, Yury Norov, Miguel Ojeda, Boqun Feng,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Onur Özkan, Bjorn Helgaas, Krzysztof Wilczyński
Cc: rust-for-linux, linux-pci, Gary Guo
From: Gary Guo <gary@garyguo.net>
Their functionality has been superseded by the `cv!` macro. Thus remove
them.
Signed-off-by: Gary Guo <gary@garyguo.net>
---
rust/kernel/num/casts.rs | 56 ------------------------------------------------
rust/kernel/pci/cap.rs | 2 +-
2 files changed, 1 insertion(+), 57 deletions(-)
diff --git a/rust/kernel/num/casts.rs b/rust/kernel/num/casts.rs
index 7e6c7dec747d..85966c570dcb 100644
--- a/rust/kernel/num/casts.rs
+++ b/rust/kernel/num/casts.rs
@@ -20,10 +20,6 @@
//! - Two extension traits, [`FromSafeCast`] and [`IntoSafeCast`], providing conversion methods
//! similar to [`From`] and [`Into`] for conversions that are safe to perform in the kernel, but
//! not supported by the standard library.
-//! - Another series of const functions (e.g. [`u64_into_u8`]) supporting the conversion of a const
-//! value from a larger type into a smaller one, provided the value fits into the destination
-//! type. This is useful if a constant is defined as a larger type, but needs to be used as a
-//! smaller one.
//! - An [`arch`] sub-module, defining more conversion functions that are only guaranteed to be
//! lossless for a given pointer size. These can only be used in code that is specific to a
//! given pointer size.
@@ -182,58 +178,6 @@ fn into_safe_cast(self) -> T {
}
}
-/// Implements lossless conversion of a constant from a larger type into a smaller one.
-macro_rules! impl_const_into {
- ($from:ty => { $($into:ty),* }) => {
- $(
- $crate::macros::paste! {
- #[doc = ::core::concat!(
- "Performs a build-time safe conversion of a [`",
- ::core::stringify!($from),
- "`] constant value into a [`",
- ::core::stringify!($into),
- "`].")]
- ///
- /// This checks at compile-time that the conversion is lossless, and triggers a build
- /// error if it isn't.
- ///
- /// # Examples
- ///
- /// ```
- /// use kernel::num::casts;
- ///
- /// // Succeeds because the value of the source fits into the destination's type.
- #[doc = ::core::concat!(
- "assert_eq!(casts::",
- ::core::stringify!($from),
- "_into_",
- ::core::stringify!($into),
- "::<1",
- ::core::stringify!($from),
- ">(), 1",
- ::core::stringify!($into),
- ");")]
- /// ```
- #[inline]
- pub const fn [<$from _into_ $into>]<const N: $from>() -> $into {
- // Make sure that the target type is smaller than the source one.
- $crate::static_assert!($from::BITS >= $into::BITS);
- // CAST: we statically enforced above that `$from` is larger than `$into`, so the
- // `as` conversion will be lossless.
- $crate::const_assert!(N >= $into::MIN as $from && N <= $into::MAX as $from);
-
- N as $into
- }
- }
- )*
- };
-}
-
-impl_const_into!(usize => { u8, u16, u32 });
-impl_const_into!(u64 => { u8, u16, u32 });
-impl_const_into!(u32 => { u8, u16 });
-impl_const_into!(u16 => { u8 });
-
/// Conversions that are only lossless for the current architecture.
///
/// # Portability
diff --git a/rust/kernel/pci/cap.rs b/rust/kernel/pci/cap.rs
index 62f263ada1b3..803b18862bb5 100644
--- a/rust/kernel/pci/cap.rs
+++ b/rust/kernel/pci/cap.rs
@@ -28,7 +28,7 @@
impl ExtCapId {
/// Single Root I/O Virtualization.
- pub const SRIOV: Self = Self(casts::u32_into_u16::<{ bindings::PCI_EXT_CAP_ID_SRIOV }>());
+ pub const SRIOV: Self = Self(cv!(bindings::PCI_EXT_CAP_ID_SRIOV));
/// Returns the raw PCIe extended capability ID.
#[inline]
---
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
change-id: 20261130-dev-num-01ef4d69fb1a
Best regards,
--
Gary Guo <gary@garyguo.net>
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 14:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 14:18 [PATCH] rust: num: remove narrowing `uX_into_uY` functions Gary Guo
2026-11-30 14:21 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox