File tree 2 files changed +5
-7
lines changed
2 files changed +5
-7
lines changed Original file line number Diff line number Diff line change 15
15
const_fn_fn_ptr_basics, // We use PhantomData<fn() -> T>
16
16
// Used for field_offset macro
17
17
const_raw_ptr_deref,
18
- const_raw_ptr_to_usize_cast,
18
+ const_maybe_uninit_as_ptr,
19
+ const_ptr_offset_from,
19
20
) ]
20
21
/*
21
22
* This is required on recent nightly
Original file line number Diff line number Diff line change @@ -18,12 +18,9 @@ macro_rules! define_extern_type {
18
18
macro_rules! field_offset {
19
19
( $target: path, $( $field: ident) ,+) => {
20
20
unsafe {
21
- /*
22
- * I'm going to assume the dereference is safe,
23
- * because of the presense of '(*uninit.as_mut_ptr()).field'
24
- * in the documentation for std::ptr::addr_of_mut
25
- */
26
- ( std:: ptr:: addr_of!( ( * ( 1 as * mut $target) ) $( . $field) * ) as usize ) - 1
21
+ let uninit = core:: mem:: MaybeUninit :: <$target>:: uninit( ) ;
22
+ let base = uninit. as_ptr( ) ;
23
+ ( core:: ptr:: addr_of!( ( * base) $( . $field) * ) . cast:: <u8 >( ) . offset_from( base as * const u8 ) )
27
24
}
28
25
}
29
26
}
You can’t perform that action at this time.
0 commit comments