Re: [PATCH v5 21/38] rust: ptr: add const_align_up() and enable inline_const feature
From: John Hubbard
Date: Sun Feb 22 2026 - 14:05:28 EST
On 2/21/26 11:46 PM, Gary Guo wrote:
On 2026-02-21 02:09, John Hubbard wrote:...
Add const_align_up<ALIGN>() to kernel::ptr as the const-compatible
equivalent of Alignable::align_up(). This uses inline_const to validate
the alignment at compile time with a clear error message.
+#[inline(always)]
+pub const fn const_align_up<const ALIGN: usize>(value: usize) -> usize {
+ const { assert!(ALIGN.is_power_of_two(), "ALIGN must be a power of two") };
+ match value.checked_add(ALIGN - 1) {
+ Some(v) => v & !(ALIGN - 1),
+ None => panic!("const_align_up: overflow"),
This is wrong. Either this function is always used in const context, in which case
you take `ALIGN` as normal function parameter and use `build_assert` and `build_error`,
or this function can be called from runtime and you shouldn't have a panic call here.
I will have another go at this, and put it in nova-core as per Miguel's
comment as well. Thanks for catching this, Gary!
thanks,
--
John Hubbard