brintos

brintos / linux-shallow public Read only

0
0
Text · 879 B · 3115ee0 Raw
35 lines · rust
1// SPDX-License-Identifier: GPL-2.02 3//! Static assert.4 5/// Static assert (i.e. compile-time assert).6///7/// Similar to C11 [`_Static_assert`] and C++11 [`static_assert`].8///9/// The feature may be added to Rust in the future: see [RFC 2790].10///11/// [`_Static_assert`]: https://en.cppreference.com/w/c/language/_Static_assert12/// [`static_assert`]: https://en.cppreference.com/w/cpp/language/static_assert13/// [RFC 2790]: https://github.com/rust-lang/rfcs/issues/279014///15/// # Examples16///17/// ```18/// static_assert!(42 > 24);19/// static_assert!(core::mem::size_of::<u8>() == 1);20///21/// const X: &[u8] = b"bar";22/// static_assert!(X[1] == b'a');23///24/// const fn f(x: i32) -> i32 {25///     x + 226/// }27/// static_assert!(f(40) == 42);28/// ```29#[macro_export]30macro_rules! static_assert {31    ($condition:expr) => {32        const _: () = core::assert!($condition);33    };34}35