File tree Expand file tree Collapse file tree 2 files changed +5
-7
lines changed Expand file tree Collapse file tree 2 files changed +5
-7
lines changed Original file line number Diff line number Diff line change 1515 const_fn_fn_ptr_basics, // We use PhantomData<fn() -> T>
1616 // Used for field_offset macro
1717 const_raw_ptr_deref,
18- const_raw_ptr_to_usize_cast,
18+ const_maybe_uninit_as_ptr,
19+ const_ptr_offset_from,
1920) ]
2021/*
2122 * 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 {
1818macro_rules! field_offset {
1919 ( $target: path, $( $field: ident) ,+) => {
2020 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 ) )
2724 }
2825 }
2926}
You can’t perform that action at this time.
0 commit comments