mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-14 06:24:53 +08:00
0f595bab9d
Add the `build_error!` and `build_assert!` macros which leverage the previously introduced `build_error` crate. Do so in a new module, called `build_assert`. The former fails the build if the code path calling it can possibly be executed. The latter asserts that a boolean expression is `true` at compile time. In particular, `build_assert!` can be used in some contexts where `static_assert!` cannot: fn f1<const N: usize>() { static_assert!(N > 1);` // Error. build_assert!(N > 1); // Build-time check. assert!(N > 1); // Run-time check. } #[inline] fn f2(n: usize) { static_assert!(n > 1); // Error. build_assert!(n > 1); // Build-time check. assert!(n > 1); // Run-time check. } Signed-off-by: Gary Guo <gary@garyguo.net> Reviewed-by: Wei Liu <wei.liu@kernel.org> [Reworded, adapted for upstream and applied latest changes] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
29 lines
616 B
Rust
29 lines
616 B
Rust
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
//! The `kernel` prelude.
|
|
//!
|
|
//! These are the most common items used by Rust code in the kernel,
|
|
//! intended to be imported by all Rust code, for convenience.
|
|
//!
|
|
//! # Examples
|
|
//!
|
|
//! ```
|
|
//! use kernel::prelude::*;
|
|
//! ```
|
|
|
|
pub use core::pin::Pin;
|
|
|
|
pub use alloc::{boxed::Box, vec::Vec};
|
|
|
|
pub use macros::{module, vtable};
|
|
|
|
pub use super::build_assert;
|
|
|
|
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};
|