From 88fa5c6a45a533a78c698a22f4b16002a3bc9fc3 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 19 May 2019 13:59:44 +0300 Subject: Improve type size assertions Now they - Tell what the new size is, when it changes - Do not require passing an identifier --- src/librustc_data_structures/macros.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/librustc_data_structures') diff --git a/src/librustc_data_structures/macros.rs b/src/librustc_data_structures/macros.rs index 029e7267c82..7fc23999284 100644 --- a/src/librustc_data_structures/macros.rs +++ b/src/librustc_data_structures/macros.rs @@ -10,3 +10,12 @@ macro_rules! static_assert { static $name: () = [()][!($test: bool) as usize]; } } + +/// Type size assertion. The first argument is a type and the second argument is its expected size. +#[macro_export] +#[allow_internal_unstable(underscore_const_names)] +macro_rules! static_assert_size { + ($ty:ty, $size:expr) => { + const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()]; + } +} -- cgit 1.4.1-3-g733a5