Skip to content

Commit 0ff3e2a

Browse files
LingManMarge Bot
LingMan
authored and
Marge Bot
committed
compiler/rust: Use std::mem::offset_of!()
It got stabilized with Rust 1.77. Reviewed-by: Faith Ekstrand <[email protected]> Reviewed-by: Karol Herbst <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31510>
1 parent 190fbbe commit 0ff3e2a

File tree

1 file changed

+1
-22
lines changed

1 file changed

+1
-22
lines changed

src/compiler/rust/nir.rs

+1-22
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,10 @@ use crate::bindings::*;
55

66
use std::ffi::{c_void, CStr};
77
use std::marker::PhantomData;
8+
use std::mem::offset_of;
89
use std::ptr::NonNull;
910
use std::str;
1011

11-
// from https://internals.rust-lang.org/t/discussion-on-offset-of/7440/2
12-
macro_rules! offset_of {
13-
($Struct:path, $field:ident) => {{
14-
// Using a separate function to minimize unhygienic hazards
15-
// (e.g. unsafety of #[repr(packed)] field borrows).
16-
// Uncomment `const` when `const fn`s can juggle pointers.
17-
18-
// const
19-
fn offset() -> usize {
20-
let u = std::mem::MaybeUninit::<$Struct>::uninit();
21-
// Use pattern-matching to avoid accidentally going through Deref.
22-
let &$Struct { $field: ref f, .. } = unsafe { &*u.as_ptr() };
23-
let o =
24-
(f as *const _ as usize).wrapping_sub(&u as *const _ as usize);
25-
// Triple check that we are within `u` still.
26-
assert!((0..=std::mem::size_of_val(&u)).contains(&o));
27-
o
28-
}
29-
offset()
30-
}};
31-
}
32-
3312
pub struct ExecListIter<'a, T> {
3413
n: &'a exec_node,
3514
offset: usize,

0 commit comments

Comments
 (0)