From 6720a34c6677e2c150cb3327a0220ff67b1b1d65 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Wed, 10 Jan 2024 21:37:59 +0000 Subject: [PATCH] Fix static_mut_ref warning --- src/unwinder/find_fde/registry.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/unwinder/find_fde/registry.rs b/src/unwinder/find_fde/registry.rs index 5341a35..5b29b10 100644 --- a/src/unwinder/find_fde/registry.rs +++ b/src/unwinder/find_fde/registry.rs @@ -32,7 +32,7 @@ unsafe fn lock_global_state() -> impl ops::DerefMut { #[cfg(feature = "libc")] { static mut MUTEX: libc::pthread_mutex_t = libc::PTHREAD_MUTEX_INITIALIZER; - unsafe { libc::pthread_mutex_lock(&mut MUTEX) }; + unsafe { libc::pthread_mutex_lock(core::ptr::addr_of_mut!(MUTEX)) }; static mut STATE: GlobalState = GlobalState { object: ptr::null_mut(), @@ -41,20 +41,22 @@ unsafe fn lock_global_state() -> impl ops::DerefMut { struct LockGuard; impl Drop for LockGuard { fn drop(&mut self) { - unsafe { libc::pthread_mutex_unlock(&mut MUTEX) }; + unsafe { libc::pthread_mutex_unlock(core::ptr::addr_of_mut!(MUTEX)) }; } } impl ops::Deref for LockGuard { type Target = GlobalState; + + #[allow(static_mut_ref)] fn deref(&self) -> &GlobalState { - unsafe { &STATE } + unsafe { &*core::ptr::addr_of!(STATE) } } } impl ops::DerefMut for LockGuard { fn deref_mut(&mut self) -> &mut GlobalState { - unsafe { &mut STATE } + unsafe { &mut *core::ptr::addr_of_mut!(STATE) } } }