Fix new function_casts_as_integer lint errors in core, std, panic_unwind and compiler crates

This commit is contained in:
Guillaume Gomez 2025-05-23 22:02:00 +02:00
parent a23b8c48a5
commit 40be1db6b8
7 changed files with 16 additions and 8 deletions

View file

@ -152,7 +152,8 @@ pub(super) fn install() {
libc::sigaltstack(&alt_stack, ptr::null_mut());
let mut sa: libc::sigaction = mem::zeroed();
sa.sa_sigaction = print_stack_trace as libc::sighandler_t;
sa.sa_sigaction =
print_stack_trace as unsafe extern "C" fn(libc::c_int) as libc::sighandler_t;
sa.sa_flags = libc::SA_NODEFER | libc::SA_RESETHAND | libc::SA_ONSTACK;
libc::sigemptyset(&mut sa.sa_mask);
for (signum, _signame) in KILL_SIGNALS {

View file

@ -151,7 +151,10 @@ fn current_dll_path() -> Result<PathBuf, String> {
unsafe {
GetModuleHandleExW(
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
PCWSTR(current_dll_path as *mut u16),
PCWSTR(
current_dll_path as fn() -> Result<std::path::PathBuf, std::string::String>
as *mut u16,
),
&mut module,
)
}

View file

@ -622,7 +622,7 @@ pub const fn forget<T: ?Sized>(_: T);
/// // Crucially, we `as`-cast to a raw pointer before `transmute`ing to a function pointer.
/// // This avoids an integer-to-pointer `transmute`, which can be problematic.
/// // Transmuting between raw pointers and function pointers (i.e., two pointer types) is fine.
/// let pointer = foo as *const ();
/// let pointer = foo as fn() -> i32 as *const ();
/// let function = unsafe {
/// std::mem::transmute::<*const (), fn() -> i32>(pointer)
/// };

View file

@ -336,6 +336,7 @@ unsafe fn throw_exception(data: Option<Box<dyn Any + Send>>) -> ! {
// In any case, we basically need to do something like this until we can
// express more operations in statics (and we may never be able to).
unsafe {
#[allow(function_casts_as_integer)]
atomic_store::<_, { AtomicOrdering::SeqCst }>(
(&raw mut THROW_INFO.pmfnUnwind).cast(),
ptr_t::new(exception_cleanup as *mut u8).raw(),
@ -352,6 +353,7 @@ unsafe fn throw_exception(data: Option<Box<dyn Any + Send>>) -> ! {
(&raw mut CATCHABLE_TYPE.pType).cast(),
ptr_t::new((&raw mut TYPE_DESCRIPTOR).cast()).raw(),
);
#[allow(function_casts_as_integer)]
atomic_store::<_, { AtomicOrdering::SeqCst }>(
(&raw mut CATCHABLE_TYPE.copyFunction).cast(),
ptr_t::new(exception_copy as *mut u8).raw(),

View file

@ -293,7 +293,7 @@ impl Backtrace {
if !Backtrace::enabled() {
return Backtrace { inner: Inner::Disabled };
}
Backtrace::create(Backtrace::capture as usize)
Backtrace::create(Backtrace::capture as fn() -> Backtrace as usize)
}
/// Forcibly captures a full backtrace, regardless of environment variable
@ -309,7 +309,7 @@ impl Backtrace {
#[stable(feature = "backtrace", since = "1.65.0")]
#[inline(never)] // want to make sure there's a frame here to remove
pub fn force_capture() -> Backtrace {
Backtrace::create(Backtrace::force_capture as usize)
Backtrace::create(Backtrace::force_capture as fn() -> Backtrace as usize)
}
/// Forcibly captures a disabled backtrace, regardless of environment

View file

@ -174,7 +174,9 @@ mod imp {
}
action.sa_flags = SA_SIGINFO | SA_ONSTACK;
action.sa_sigaction = signal_handler as sighandler_t;
action.sa_sigaction = signal_handler
as unsafe extern "C" fn(i32, *mut libc::siginfo_t, *mut libc::c_void)
as sighandler_t;
// SAFETY: only overriding signals if the default is set
unsafe { sigaction(signal, &action, ptr::null_mut()) };
}

View file

@ -155,7 +155,7 @@ macro_rules! compat_fn_with_fallback {
/// When that is called it attempts to load the requested symbol.
/// If it succeeds, `PTR` is set to the address of that symbol.
/// If it fails, then `PTR` is set to `fallback`.
static PTR: Atomic<*mut c_void> = AtomicPtr::new(load as *mut _);
static PTR: Atomic<*mut c_void> = AtomicPtr::new(load as unsafe extern "system" fn($($argname: $argtype),*) -> $rettype as *mut _);
unsafe extern "system" fn load($($argname: $argtype),*) -> $rettype {
unsafe {
@ -171,7 +171,7 @@ macro_rules! compat_fn_with_fallback {
PTR.store(f.as_ptr(), Ordering::Relaxed);
mem::transmute(f)
} else {
PTR.store(fallback as *mut _, Ordering::Relaxed);
PTR.store(fallback as unsafe extern "system" fn($($argname: $argtype),*) -> $rettype as *mut _, Ordering::Relaxed);
fallback
}
}