diff --git a/src/compiler/rust/nir.rs b/src/compiler/rust/nir.rs index fbd20cdb924..055948461d9 100644 --- a/src/compiler/rust/nir.rs +++ b/src/compiler/rust/nir.rs @@ -5,31 +5,10 @@ use crate::bindings::*; use std::ffi::{c_void, CStr}; use std::marker::PhantomData; +use std::mem::offset_of; use std::ptr::NonNull; use std::str; -// from https://internals.rust-lang.org/t/discussion-on-offset-of/7440/2 -macro_rules! offset_of { - ($Struct:path, $field:ident) => {{ - // Using a separate function to minimize unhygienic hazards - // (e.g. unsafety of #[repr(packed)] field borrows). - // Uncomment `const` when `const fn`s can juggle pointers. - - // const - fn offset() -> usize { - let u = std::mem::MaybeUninit::<$Struct>::uninit(); - // Use pattern-matching to avoid accidentally going through Deref. - let &$Struct { $field: ref f, .. } = unsafe { &*u.as_ptr() }; - let o = - (f as *const _ as usize).wrapping_sub(&u as *const _ as usize); - // Triple check that we are within `u` still. - assert!((0..=std::mem::size_of_val(&u)).contains(&o)); - o - } - offset() - }}; -} - pub struct ExecListIter<'a, T> { n: &'a exec_node, offset: usize,