]> git.lizzy.rs Git - rust.git/blob - src/librustc_data_structures/macros.rs
Auto merge of #61874 - jonas-schievink:remove-rem-output-default, r=Centril
[rust.git] / src / librustc_data_structures / macros.rs
1 /// A simple static assertion macro.
2 #[macro_export]
3 #[cfg_attr(bootstrap, allow_internal_unstable(type_ascription, underscore_const_names))]
4 #[cfg_attr(not(bootstrap), allow_internal_unstable(type_ascription))]
5 macro_rules! static_assert {
6     ($test:expr) => {
7         // Use the bool to access an array such that if the bool is false, the access
8         // is out-of-bounds.
9         #[allow(dead_code)]
10         const _: () = [()][!($test: bool) as usize];
11     }
12 }
13
14 /// Type size assertion. The first argument is a type and the second argument is its expected size.
15 #[macro_export]
16 #[cfg_attr(bootstrap, allow_internal_unstable(underscore_const_names))]
17 macro_rules! static_assert_size {
18     ($ty:ty, $size:expr) => {
19         const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()];
20     }
21 }