From 190fbbe1d66925a9927854124b0568a3c913c99e Mon Sep 17 00:00:00 2001 From: LingMan <18294-LingMan@users.noreply.gitlab.freedesktop.org> Date: Thu, 3 Oct 2024 16:27:47 +0200 Subject: [PATCH] nak/hw_test: Use std::mem::offset_of!() It got stabilized with Rust 1.77. Reviewed-by: Faith Ekstrand Reviewed-by: Karol Herbst Part-of: --- src/nouveau/compiler/nak/hw_tests.rs | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/src/nouveau/compiler/nak/hw_tests.rs b/src/nouveau/compiler/nak/hw_tests.rs index 71d70b61dc5..5926cf8c669 100644 --- a/src/nouveau/compiler/nak/hw_tests.rs +++ b/src/nouveau/compiler/nak/hw_tests.rs @@ -10,31 +10,10 @@ use crate::sm70::ShaderModel70; use acorn::Acorn; use compiler::cfg::CFGBuilder; use nak_bindings::*; +use std::mem::offset_of; use std::str::FromStr; use std::sync::OnceLock; -// 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() - }}; -} - struct RunSingleton { sm: Box, run: Runner,