summary refs log tree commit diff
path: root/src/librustc_data_structures
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-05-19 13:59:44 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-05-19 13:59:44 +0300
commit88fa5c6a45a533a78c698a22f4b16002a3bc9fc3 (patch)
tree7de7f6bc6d9aa974bbddbe37ab2641290eb3c12e /src/librustc_data_structures
parente0d2f7462b07039c7327d8331272a804c025b047 (diff)
downloadrust-88fa5c6a45a533a78c698a22f4b16002a3bc9fc3.tar.gz
rust-88fa5c6a45a533a78c698a22f4b16002a3bc9fc3.zip
Improve type size assertions
Now they
- Tell what the new size is, when it changes
- Do not require passing an identifier
Diffstat (limited to 'src/librustc_data_structures')
-rw-r--r--src/librustc_data_structures/macros.rs9
1 files changed, 9 insertions, 0 deletions
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>()];
+    }
+}