Re: [PATCH v3 2/4] rust: add `const_assert!` macro
From: Gary Guo
Date: Thu Mar 19 2026 - 10:40:04 EST
On Thu Mar 19, 2026 at 2:12 PM GMT, Alice Ryhl wrote:
> On Thu, Mar 19, 2026 at 12:16:46PM +0000, Gary Guo wrote:
>> From: Gary Guo <gary@xxxxxxxxxxx>
>>
>> The macro is a more powerful version of `static_assert!` for use inside
>> function contexts. This is powered by inline consts, so enable the feature
>> for old compiler versions that does not have it stably.
>>
>> While it is possible already to write `const { assert!(...) }`, this
>> provides a short hand that is more uniform with other assertions. It also
>> formats nicer with rustfmt where it will not be formatted into multiple
>> lines.
>>
>> Two users that would route via the Rust tree are converted.
>>
>> Reviewed-by: Yury Norov <ynorov@xxxxxxxxxx>
>> Signed-off-by: Gary Guo <gary@xxxxxxxxxxx>
>
> Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
>
> It may be worth to mention in docs that const_assert! may only be
> checked if the function it appears in has a caller. Whereas
> static_assert! is always checked no matter what.
>
> Alice
I explained this in patch 3 on why `static_assert!` is preferred over
`const_assert!`. Given that we recommend `const_assert!` only when it refers to
generics, the check is inherently tied to a specific instance anyway, so I don't
think it needs to be mentioned in the item doc.
Best,
Gary