Re: [PATCH v6] rust: kernel: introduce `unsafe_precondition_assert!` macro

From: Miguel Ojeda

Date: Mon Feb 02 2026 - 02:23:17 EST


On Tue, Oct 7, 2025 at 11:53 PM Ritvik Gupta <ritvikfoss@xxxxxxxxx> wrote:
>
> Introduce a new `safety` module containing `unsafe_precondition_assert!`
> macro. It is a wrapper around `debug_assert!`, intended for validating
> pre-conditions of unsafe function.
>
> When `CONFIG_RUST_DEBUG_ASSERTIONS` flag is enabled, this macro performs
> runtime checks to ensure that the preconditions for unsafe function hold.
> Otherwise, the macro is a no-op.
>
> Suggested-by: Miguel Ojeda <ojeda@xxxxxxxxxx>
> Link: https://github.com/Rust-for-Linux/linux/issues/1162
> Link: https://rust-for-linux.zulipchat.com/#narrow/channel/291566-Library/topic/.60unsafe_precondition_assert.60.20macro/with/528457452
> Signed-off-by: Ritvik Gupta <ritvikfoss@xxxxxxxxx>

Applied to `rust-next` -- thanks everyone!

[ Added trailing periods, intra-doc link, "a" in "is a no-op" and `()`
to function reference. Removed plural in assertion message and title
of macro. Reworded slightly. - Miguel ]

Cheers,
Miguel