Re: [PATCH v4 1/2] rust: kernel: create `overflow_assert!` macro
From: Antonio Hickey
Date: Sun Jul 20 2025 - 12:17:59 EST
Tamir Duberstein wrote:
> On Sat, Jun 28, 2025 at 10:43 PM Antonio Hickey
> <contact@xxxxxxxxxxxxxxxxx> wrote:
> > +//! Overflow assertion.
> > +
> > +/// Verifies at runtime that an expression is within an expected bound.
>
> This is a strange comment, imo. The only thing special about this
> macro relative to a plain `assert` is that it disabled when
> CONFIG_RUST_OVERFLOW_CHECKS=n.
Special yes, but it also documents the intent of the `assert`.
I did include a comment about the conditional behaviour with
CONFIG_RUST_OVERFLOW_CHECKS being enabled/disabled.
I'm open to rewording this doc comment to be better though.
I should also add information about the optional panic message
like the `static_assert` does as well, what about something like:
```
/// Overflow assertion.
///
/// Runtime assertion that an expression is within an expected bounds.
///
/// This macro is only enabled when `CONFIG_RUST_OVERFLOW_CHECKS` is true.
///
/// An optional panic message can be supplied after the expression.
/// Currently only a string literal without formatting is supported
/// due to constness limitations of the [`assert!`] macro.
```
Thanks
>
> > +///
> > +/// This macro is only active when `CONFIG_RUST_OVERFLOW_CHECKS` is enabled.