Skip to content

Commit c486b33

Browse files
committed
rust: Prefer build_assert! to assert!
Signed-off-by: Gary Guo <[email protected]>
1 parent 306313b commit c486b33

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

rust/kernel/print.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::c_types::c_int;
1818
#[doc(hidden)]
1919
pub mod format_strings {
2020
use crate::bindings;
21+
use crate::build_assert;
2122

2223
/// The length we copy from the `KERN_*` kernel prefixes.
2324
const LENGTH_PREFIX: usize = 2;
@@ -33,13 +34,13 @@ pub mod format_strings {
3334
/// [`printk`]: ../../../../include/linux/printk.h
3435
const fn generate(is_cont: bool, prefix: &[u8; 3]) -> [u8; LENGTH] {
3536
// Ensure the `KERN_*` macros are what we expect.
36-
assert!(prefix[0] == b'\x01');
37+
build_assert!(prefix[0] == b'\x01');
3738
if is_cont {
38-
assert!(prefix[1] == b'c');
39+
build_assert!(prefix[1] == b'c');
3940
} else {
40-
assert!(prefix[1] >= b'0' && prefix[1] <= b'7');
41+
build_assert!(prefix[1] >= b'0' && prefix[1] <= b'7');
4142
}
42-
assert!(prefix[2] == b'\x00');
43+
build_assert!(prefix[2] == b'\x00');
4344

4445
let suffix: &[u8; LENGTH - LENGTH_PREFIX] = if is_cont {
4546
b"%.*s\0\0\0\0\0"

0 commit comments

Comments
 (0)