From 717c102f55136653c585a45d6d47fae9a62b2312 Mon Sep 17 00:00:00 2001 From: MSxDOS <15524350+MSxDOS@users.noreply.github.com> Date: Tue, 16 Jul 2019 21:09:33 +0300 Subject: [PATCH] Update FIELD_OFFSET It may now be used in constants e.g. for static assertions (but not inside constant functions, yet, see https://github.com/rust-lang/rust/issues/51909) --- src/macros.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/macros.rs b/src/macros.rs index 1dff0c2..ace5f94 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -28,7 +28,16 @@ macro_rules! EXTERN { macro_rules! FIELD_OFFSET { ($_type:ty, $field:ident$(.$cfields:ident)*) => { unsafe { - &(*$crate::_core::ptr::null::<$_type>()).$field$(.$cfields)* as *const _ as usize + union Transmuter { + p: *const T, + r: &'static T, + i: usize, + } + Transmuter { + r: &(Transmuter { + p: $crate::_core::ptr::null::<$_type>() + }.r).$field$(.$cfields)* + }.i } }; }