Re: [PATCH v5] rust: kernel: add support for bits/genmask macros

Alexandre Courbot
2025-05-22T08:23:37Z

On Thu May 22, 2025 at 5:21 PM JST, Miguel Ojeda wrote:
> On Thu, May 22, 2025 at 5:17 AM Alexandre Courbot <acourbot@nvidia.com> wrote:
>>
>> // Compile-time error if `n` is out of bounds.
>> pub const fn bit_u32(n: u32) -> u32 {
>> // Only accept values known at compile-time.
>> static_assert!(n < u32::BITS);
>> 1u32 << n
>> }
>
> I think this was meant to be `build_assert!`. `static_assert!` cannot
> be used when the value is potentially not known.

Indeed, thanks for correcting!

>
> (It would need to be `#[inline]` too).

Like everything else in this module. :)