diff options
author | Miguel Ojeda <ojeda@kernel.org> | 2022-11-10 17:41:36 +0100 |
---|---|---|
committer | Miguel Ojeda <ojeda@kernel.org> | 2022-12-04 01:59:16 +0100 |
commit | ef9e37973c3a50497c943e70d577dad10a8e41f2 (patch) | |
tree | c37456e5676a9169156ad4a03926655dfc27f064 /rust/kernel/prelude.rs | |
parent | rust: std_vendor: add `dbg!` macro based on `std`'s one (diff) | |
download | linux-ef9e37973c3a50497c943e70d577dad10a8e41f2.tar.xz linux-ef9e37973c3a50497c943e70d577dad10a8e41f2.zip |
rust: static_assert: add `static_assert!` macro
Add the `static_assert!` macro, which is a compile-time assert, similar
to the C11 `_Static_assert` and C++11 `static_assert` declarations [1,2].
Do so in a new module, called `static_assert`.
For instance:
static_assert!(42 > 24);
static_assert!(core::mem::size_of::<u8>() == 1);
const X: &[u8] = b"bar";
static_assert!(X[1] == b'a');
const fn f(x: i32) -> i32 {
x + 2
}
static_assert!(f(40) == 42);
Link: https://en.cppreference.com/w/c/language/_Static_assert [1]
Link: https://en.cppreference.com/w/cpp/language/static_assert [2]
Co-developed-by: Alex Gaynor <alex.gaynor@gmail.com>
Signed-off-by: Alex Gaynor <alex.gaynor@gmail.com>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust/kernel/prelude.rs')
-rw-r--r-- | rust/kernel/prelude.rs | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/rust/kernel/prelude.rs b/rust/kernel/prelude.rs index 345fc9075d1f..178fe8e6cb6d 100644 --- a/rust/kernel/prelude.rs +++ b/rust/kernel/prelude.rs @@ -19,6 +19,8 @@ pub use macros::{module, vtable}; pub use super::{dbg, pr_alert, pr_crit, pr_debug, pr_emerg, pr_err, pr_info, pr_notice, pr_warn}; +pub use super::static_assert; + pub use super::error::{code::*, Error, Result}; pub use super::{str::CStr, ThisModule}; |