Skip to content

Commit c20475c

Browse files
devnexentgross35
authored andcommitted
macros: Update offset_of!
- assert! access from core. - nested unsafe raises an error on older rust compilers on CI. [ re-split commits as authorized by the author, and update the commit summary - Trevor ]
1 parent 6383ad8 commit c20475c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/macros.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,12 @@ macro_rules! offset_of {
418418
let $Ty { $field: _, .. };
419419
let data = core::mem::MaybeUninit::<$Ty>::uninit();
420420
let ptr = data.as_ptr();
421+
// nested unsafe, see f!
422+
#[allow(unused_unsafe)]
421423
// SAFETY: computed address is inbounds since we have a stack alloc for T
422424
let fptr = unsafe { core::ptr::addr_of!((*ptr).$field) };
423425
let off = (fptr as usize).checked_sub(ptr as usize).unwrap();
424-
assert!(off <= core::mem::size_of::<$Ty>());
426+
core::assert!(off <= core::mem::size_of::<$Ty>());
425427
off
426428
}};
427429
}

0 commit comments

Comments
 (0)