From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796048312; b=f9VSPRW2lEWx1da7zb/GEZBU4ep662zBubcBg+koB/pz4Y4cympgyIy4iIt9cngxFF0O cw4hpebpIVhYPdd1K2MabPQpci7ohSaawY8Ck4pDot/czynKEB7yXIqCq/6H7GCn17L3I niivLF589T3g4vw3Shb4MnXly3/H7x9S3wCi7fnk25aPYH9fNq9pUdsUiDac7CsySemVV vNXawiH/0lYWC2wZDTiqkpyocErXIS4se65mj5bXTdU3wNLQgLtxm7lwppJ6zF//HWlFc 4P3U3aiZvlQHG5QuDEemU2MycVld2iX3Tmg7N8x11oLLqN7nn9aUhK+6zFwn3WhGdSw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796048312; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:X-B4-Tracking:X-Change-ID:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=+w/KdTgpa022Y4dgL6Mic2tnctVuk3cIr/+rDkZaeWo=; b=N5LQ0vvjH82Js9w51bYDQLLKENZUIYpU6SIguNdBfpvUvxChL1owQfDA5U5DYTxpIVRb OxgaY0Zih2qY+wtH5G+pUX+THZyMBjK3heckCEUHHMbpUoPSw+pWlNQ+fG4UvHl+4lbV/ Zxb0UK1phx5fc314keweIGbl7x26BZgexj51F7BbUS3PhdmU6UuU+1kf32K00le5iiIQS bxX5ABlIoS/6MBnrTlMar7AVUIJ2wr0QphSESjdDXUro/TVgxwo24zGzXx4j9dBXIzYEY mkIu/F2aOmEY6u43UQya+Y9QdAUr3/D++1Po6e7TimaKpVOzL42zZGe5PZC7qMmZPsQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TUswfYNI; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B095606A325; Mon, 30 Nov 2026 14:18:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TUswfYNI Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1E8E1F00898; Mon, 30 Nov 2026 14:18:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796048312; bh=+w/KdTgpa022Y4dgL6Mic2tnctVuk3cIr/+rDkZaeWo=; h=From:Date:Subject:To:Cc; b=TUswfYNIIz5e6U+6FK0fmN9RxllSVzmqXha0t0OJjiWakOxx/0k9TOJqze3evwzzl ewXh4dm2BbyDkAQxzckc6HOsenBqrIh1oE1JapL5VqLxenQc8alGtweZPOLPfYw2Z9 xBaWS1nneTGypYuyTKAL43iP3kirq18LoHXy3KP9qDWF+/nZhoWQXF8znhd4r1QpMY dG9wXM1eJpAjfdBKVo/XDGy2vOwY5Yfbd9l8abFDwJ88oIN1E1QbTBMDnXYa4nFo/+ eNGS7w9zi4i12+qyimKOTG6DUQ8dc7RtwVbJ7cMqnC5YzjbVyH1B/AnMMJDk20nXZC Khe5cz4nuPZCw== From: Gary Guo Date: Mon, 30 Nov 2026 14:18:27 +0000 Subject: [PATCH] rust: num: remove narrowing `uX_into_uY` functions X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261130-dev-num-v1-1-a1b907bfd440@garyguo.net> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/yWM2wrCMBBEf6Xss4tJlYL+iviQy8auYJTdpBRK/ 91EXwbOcGY2UBImheuwgdDCyu/cwB4GCLPLD0KOjWE042TtyWCkBXN9obGUznG6JG8dNPsjlHj 9Pd3uf9bqnxRKn3fDOyX04nKYeyVVy7EHZloL7PsXn+Ktt4wAAAA= X-Change-ID: 20261130-dev-num-01ef4d69fb1a To: Alexandre Courbot , Yury Norov , Miguel Ojeda , Boqun Feng , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , =?utf-8?q?Onur_=C3=96zkan?= , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= Cc: rust-for-linux@vger.kernel.org, linux-pci@vger.kernel.org, Gary Guo X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796048308; l=4125; i=gary@garyguo.net; s=20221204; h=from:subject:message-id; bh=zoVM6PdV4w6EvnM+iKH0v0wsIej0fuJCE8GOrHCEir0=; b=IJTW328cVyr2jx8+A/d2UdNNiYUFZXtoO4fOFhI5/N8II4XUCV+YLQ5Et+FbJroM//W2PjzWd wl7JOu5ylZ7Cy1I9glTmMSBmnzF8fEL3IeVwiQzz4itcjTEZEm7xzgl X-Developer-Key: i=gary@garyguo.net; a=ed25519; pk=vB3uIX95SM4eVrIqo1DWNWKDKD2xzB+yLLLr0yOPYMo= From: Gary Guo Their functionality has been superseded by the `cv!` macro. Thus remove them. Signed-off-by: Gary Guo --- 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>]() -> $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