Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: ptr: replace unneeded use of `build_assert`

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>

authored by

Alexandre Courbot and committed by
Miguel Ojeda
84b1b49e 1b18b37a

+6 -6
+6 -6
rust/kernel/ptr.rs
··· 5 5 use core::mem::align_of; 6 6 use core::num::NonZero; 7 7 8 - use crate::build_assert; 9 - 10 8 /// Type representing an alignment, which is always a power of two. 11 9 /// 12 10 /// It is used to validate that a given value is a valid alignment, and to perform masking and ··· 38 40 /// ``` 39 41 #[inline(always)] 40 42 pub const fn new<const ALIGN: usize>() -> Self { 41 - build_assert!( 42 - ALIGN.is_power_of_two(), 43 - "Provided alignment is not a power of two." 44 - ); 43 + const { 44 + assert!( 45 + ALIGN.is_power_of_two(), 46 + "Provided alignment is not a power of two." 47 + ); 48 + } 45 49 46 50 // INVARIANT: `align` is a power of two. 47 51 // SAFETY: `align` is a power of two, and thus non-zero.