]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rust: ptr: replace unneeded use of `build_assert`
authorAlexandre Courbot <acourbot@nvidia.com>
Tue, 16 Dec 2025 08:24:49 +0000 (17:24 +0900)
committerMiguel Ojeda <ojeda@kernel.org>
Mon, 19 Jan 2026 00:13:22 +0000 (01:13 +0100)
Since `ALIGN` is a const parameter, this assertion can be done in const
context using the `assert!` macro.

Suggested-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://patch.msgid.link/20251216-ptr_assert-v1-1-d8b2d5c5741d@nvidia.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/ptr.rs

index e3893ed04049d24427e241d2705ad5df8307c1e7..5b6a382637fef11e9c0ae9122906422a970d7fcd 100644 (file)
@@ -5,8 +5,6 @@
 use core::mem::align_of;
 use core::num::NonZero;
 
-use crate::build_assert;
-
 /// Type representing an alignment, which is always a power of two.
 ///
 /// It is used to validate that a given value is a valid alignment, and to perform masking and
@@ -40,10 +38,12 @@ impl Alignment {
     /// ```
     #[inline(always)]
     pub const fn new<const ALIGN: usize>() -> Self {
-        build_assert!(
-            ALIGN.is_power_of_two(),
-            "Provided alignment is not a power of two."
-        );
+        const {
+            assert!(
+                ALIGN.is_power_of_two(),
+                "Provided alignment is not a power of two."
+            );
+        }
 
         // INVARIANT: `align` is a power of two.
         // SAFETY: `align` is a power of two, and thus non-zero.