diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 0e2e869a920..6c1d20f36e2 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -355,8 +355,8 @@ impl<'a> ArgumentV1<'a> { // We are type punning a bit here: USIZE_MARKER only takes an &usize but // formatter takes an &Opaque. Rust understandably doesn't think we should compare // the function pointers if they don't have the same signature, so we cast to - // pointers to convince it that we know what we're doing. - if self.formatter as *mut u8 == USIZE_MARKER as *mut u8 { + // usizes to tell it that we just want to compare addresses. + if self.formatter as usize == USIZE_MARKER as usize { // SAFETY: The `formatter` field is only set to USIZE_MARKER if // the value is a usize, so this is safe Some(unsafe { *(self.value as *const _ as *const usize) }) diff --git a/library/std/src/backtrace.rs b/library/std/src/backtrace.rs index 3b0922ad16f..05e9b2eb6bc 100644 --- a/library/std/src/backtrace.rs +++ b/library/std/src/backtrace.rs @@ -293,7 +293,7 @@ impl Backtrace { if !Backtrace::enabled() { return Backtrace { inner: Inner::Disabled }; } - Backtrace::create((Backtrace::capture as *mut ()).addr()) + Backtrace::create(Backtrace::capture as usize) } /// Forcibly captures a full backtrace, regardless of environment variable @@ -308,7 +308,7 @@ impl Backtrace { /// parts of code. #[inline(never)] // want to make sure there's a frame here to remove pub fn force_capture() -> Backtrace { - Backtrace::create((Backtrace::force_capture as *mut ()).addr()) + Backtrace::create(Backtrace::force_capture as usize) } /// Forcibly captures a disabled backtrace, regardless of environment diff --git a/library/std/src/sys/unix/weak.rs b/library/std/src/sys/unix/weak.rs index c9606aec3f6..da63c068384 100644 --- a/library/std/src/sys/unix/weak.rs +++ b/library/std/src/sys/unix/weak.rs @@ -22,10 +22,9 @@ // that, we'll just allow that some unix targets don't use this module at all. #![allow(dead_code, unused_macros)] -use crate::ffi::{c_void, CStr}; +use crate::ffi::CStr; use crate::marker::PhantomData; use crate::mem; -use crate::ptr; use crate::sync::atomic::{self, AtomicUsize, Ordering}; // We can use true weak linkage on ELF targets. @@ -130,25 +129,25 @@ impl DlsymWeak { // Cold because it should only happen during first-time initialization. #[cold] unsafe fn initialize(&self) -> Option { - assert_eq!(mem::size_of::(), mem::size_of::<*mut ()>()); + assert_eq!(mem::size_of::(), mem::size_of::()); let val = fetch(self.name); // This synchronizes with the acquire fence in `get`. - self.addr.store(val.addr(), Ordering::Release); + self.addr.store(val, Ordering::Release); - match val.addr() { + match val { 0 => None, - _ => Some(mem::transmute_copy::<*mut c_void, F>(&val)), + addr => Some(mem::transmute_copy::(&addr)), } } } -unsafe fn fetch(name: &str) -> *mut c_void { +unsafe fn fetch(name: &str) -> usize { let name = match CStr::from_bytes_with_nul(name.as_bytes()) { Ok(cstr) => cstr, - Err(..) => return ptr::null_mut(), + Err(..) => return 0, }; - libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr()) + libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr()) as usize } #[cfg(not(any(target_os = "linux", target_os = "android")))]