Skip to content

Commit

Permalink
Update FIELD_OFFSET
Browse files Browse the repository at this point in the history
It may now be used in constants e.g. for static assertions (but not inside constant functions, yet, see rust-lang/rust#51909)
  • Loading branch information
MSxDOS committed Jul 16, 2019
1 parent c384a16 commit 717c102
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: 'static> {
p: *const T,
r: &'static T,
i: usize,
}
Transmuter {
r: &(Transmuter {
p: $crate::_core::ptr::null::<$_type>()
}.r).$field$(.$cfields)*
}.i
}
};
}
Expand Down

0 comments on commit 717c102

Please sign in to comment.