Re: [PATCH 2/2] rust: add `const_assert!` macro

From: Gary Guo

Date: Fri Feb 06 2026 - 16:49:10 EST


On Fri Feb 6, 2026 at 9:30 PM GMT, Benno Lossin wrote:
> On Fri Feb 6, 2026 at 6:12 PM CET, Gary Guo wrote:
>> +/// Assertion during constant evaluation.
>> +///
>> +/// This is a more powerful version of `static_assert` that can refer to generics inside functions
>> +/// or implementation blocks. However, it also have a limitation where it can only appear in places
>> +/// where statements can appear; for example, you cannot use it as an item in the module.
>> +///
>> +/// [`static_assert!`] should be preferred where possible.
>> +///
>> +/// # Examples
>> +///
>> +/// When the condition refers to generic parameters [`static_assert!`] cannot be used.
>> +/// Use `const_assert!` in this scenario.
>> +/// ```
>> +/// fn foo<const N: usize>() {
>> +/// // `static_assert!(N > 1);` is not allowed
>> +/// const_assert!(N > 1); // Compile-time check
>> +/// build_assert!(N > 1); // Build-time check
>
> I think having "Build-time check" here is a bit confusing, how about we
> change it to "Link-time check"? Since a "Compile-time check" also is
> done at "Build-time"

This is the intentional phrasing that I used for `build_assert!` when I created
it, for the reason that `build_assert!` ensure that it will fire, at latest,
link time. However, if you actually use such methods with CTFE, it will error
earlier. So it is "at latest link-time check", so I decided to just use
"build-time".

Best,
Gary

>
> Cheers,
> Benno