[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANiq72=Lu1nwW0-MP-nJ57v8hh56c6V+r=RsnR6g41Em8MvxCg@mail.gmail.com>
Date: Mon, 19 May 2025 19:57:19 +0200
From: Miguel Ojeda <miguel.ojeda.sandonis@...il.com>
To: Daniel Almeida <daniel.almeida@...labora.com>
Cc: Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>, Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
Danilo Krummrich <dakr@...nel.org>, linux-kernel@...r.kernel.org,
rust-for-linux@...r.kernel.org, Fiona Behrens <me@...enk.dev>
Subject: Re: [PATCH v5] rust: kernel: add support for bits/genmask macros
On Tue, May 13, 2025 at 8:52 PM Daniel Almeida
<daniel.almeida@...labora.com> wrote:
>
> I have been staring at this for a little while.
>
> I wonder what is everyone's opinions on an extra set of:
>
> // e.g.: for u32
> const fn const_genmask_u32<const H: u32, const L: u32>() -> u32 {
> crate::build_assert!(H >= L);
> ...
> }
>
> ..on top of the current genmask functions we already have?
It seems you want `consteval` from C++ :)
Without having thought about the particular use case, just a quick
note: if you have const generics, then you can use `const { assert!(H
>= L); }` instead.
Nowadays `.unwrap()` on `Option` is `const`, but not `Result`'s. That
would be a way to have a single fallible function that allows users to
decide to unwrap in a const context or use them fallibly for runtime
values. Another is having a custom `const` unwrap for those concrete
`Result`s.
Cheers,
Miguel
Powered by blists - more mailing lists