]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
rust: add `const_assert!` macro
authorGary Guo <gary@garyguo.net>
Thu, 19 Mar 2026 12:16:46 +0000 (12:16 +0000)
committerMiguel Ojeda <ojeda@kernel.org>
Mon, 30 Mar 2026 00:03:49 +0000 (02:03 +0200)
commit560a7a9b9267fbe31a68270ca0ad22b6a4db44a5
treefc1b22fd60a0e9a64a8e01ea42015a61df6dba64
parentabfe5ee9971249b91020b5053afcaad43837336a
rust: add `const_assert!` macro

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@nvidia.com>
Signed-off-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Link: https://patch.msgid.link/20260319121653.2975748-3-gary@kernel.org
[ Rebased. Fixed period typo. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/build_assert.rs
rust/kernel/num/bounded.rs
rust/kernel/prelude.rs
rust/kernel/ptr.rs
scripts/Makefile.build