Re: [PATCH v6 4/9] rust: num: make Bounded::get const
From: Alice Ryhl
Date: Mon Feb 16 2026 - 03:57:07 EST
On Mon, Feb 16, 2026 at 05:04:40PM +0900, Alexandre Courbot wrote:
> There is a need to access the inner value of a `Bounded` in const
> context, notably for bitfields and registers. Remove the invariant check
> of `Bounded::get`, which allows us to make it const.
>
> Signed-off-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
> ---
> rust/kernel/num/bounded.rs | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/rust/kernel/num/bounded.rs b/rust/kernel/num/bounded.rs
> index 8e4c08924d96..b09b93cd0c5c 100644
> --- a/rust/kernel/num/bounded.rs
> +++ b/rust/kernel/num/bounded.rs
> @@ -379,6 +379,9 @@ pub fn from_expr(expr: T) -> Self {
>
> /// Returns the wrapped value as the backing type.
> ///
> + /// This is similar to the [`Deref`] implementation, but doesn't enforce the size invariant of
> + /// the [`Bounded`], which might produce slightly less optimal code.
The unreachable_unchecked() hint is const, so I see no reason you
couldn't add the same call in `fn get`.
Alice