Skip to content

Commit edcae85

Browse files
Fix new function_casts_as_integer lint errors in core, std, panic_unwind and compiler crates
1 parent 56f3007 commit edcae85

File tree

7 files changed

+16
-8
lines changed

7 files changed

+16
-8
lines changed

compiler/rustc_driver_impl/src/signal_handler.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ pub(super) fn install() {
152152
libc::sigaltstack(&alt_stack, ptr::null_mut());
153153

154154
let mut sa: libc::sigaction = mem::zeroed();
155-
sa.sa_sigaction = print_stack_trace as libc::sighandler_t;
155+
sa.sa_sigaction =
156+
print_stack_trace as unsafe extern "C" fn(libc::c_int) as libc::sighandler_t;
156157
sa.sa_flags = libc::SA_NODEFER | libc::SA_RESETHAND | libc::SA_ONSTACK;
157158
libc::sigemptyset(&mut sa.sa_mask);
158159
for (signum, _signame) in KILL_SIGNALS {

compiler/rustc_session/src/filesearch.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ fn current_dll_path() -> Result<PathBuf, String> {
151151
unsafe {
152152
GetModuleHandleExW(
153153
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
154-
PCWSTR(current_dll_path as *mut u16),
154+
PCWSTR(
155+
current_dll_path as fn() -> Result<std::path::PathBuf, std::string::String>
156+
as *mut u16,
157+
),
155158
&mut module,
156159
)
157160
}

library/core/src/intrinsics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ pub const fn forget<T: ?Sized>(_: T);
618618
/// // Crucially, we `as`-cast to a raw pointer before `transmute`ing to a function pointer.
619619
/// // This avoids an integer-to-pointer `transmute`, which can be problematic.
620620
/// // Transmuting between raw pointers and function pointers (i.e., two pointer types) is fine.
621-
/// let pointer = foo as *const ();
621+
/// let pointer = foo as fn() -> i32 as *const ();
622622
/// let function = unsafe {
623623
/// std::mem::transmute::<*const (), fn() -> i32>(pointer)
624624
/// };

library/panic_unwind/src/seh.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ unsafe fn throw_exception(data: Option<Box<dyn Any + Send>>) -> ! {
336336
// In any case, we basically need to do something like this until we can
337337
// express more operations in statics (and we may never be able to).
338338
unsafe {
339+
#[allow(function_casts_as_integer)]
339340
atomic_store::<_, { AtomicOrdering::SeqCst }>(
340341
(&raw mut THROW_INFO.pmfnUnwind).cast(),
341342
ptr_t::new(exception_cleanup as *mut u8).raw(),
@@ -352,6 +353,7 @@ unsafe fn throw_exception(data: Option<Box<dyn Any + Send>>) -> ! {
352353
(&raw mut CATCHABLE_TYPE.pType).cast(),
353354
ptr_t::new((&raw mut TYPE_DESCRIPTOR).cast()).raw(),
354355
);
356+
#[allow(function_casts_as_integer)]
355357
atomic_store::<_, { AtomicOrdering::SeqCst }>(
356358
(&raw mut CATCHABLE_TYPE.copyFunction).cast(),
357359
ptr_t::new(exception_copy as *mut u8).raw(),

library/std/src/backtrace.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl Backtrace {
293293
if !Backtrace::enabled() {
294294
return Backtrace { inner: Inner::Disabled };
295295
}
296-
Backtrace::create(Backtrace::capture as usize)
296+
Backtrace::create(Backtrace::capture as fn() -> Backtrace as usize)
297297
}
298298

299299
/// Forcibly captures a full backtrace, regardless of environment variable
@@ -309,7 +309,7 @@ impl Backtrace {
309309
#[stable(feature = "backtrace", since = "1.65.0")]
310310
#[inline(never)] // want to make sure there's a frame here to remove
311311
pub fn force_capture() -> Backtrace {
312-
Backtrace::create(Backtrace::force_capture as usize)
312+
Backtrace::create(Backtrace::force_capture as fn() -> Backtrace as usize)
313313
}
314314

315315
/// Forcibly captures a disabled backtrace, regardless of environment

library/std/src/sys/pal/unix/stack_overflow.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ mod imp {
174174
}
175175

176176
action.sa_flags = SA_SIGINFO | SA_ONSTACK;
177-
action.sa_sigaction = signal_handler as sighandler_t;
177+
action.sa_sigaction = signal_handler
178+
as unsafe extern "C" fn(i32, *mut libc::siginfo_t, *mut libc::c_void)
179+
as sighandler_t;
178180
// SAFETY: only overriding signals if the default is set
179181
unsafe { sigaction(signal, &action, ptr::null_mut()) };
180182
}

library/std/src/sys/pal/windows/compat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ macro_rules! compat_fn_with_fallback {
155155
/// When that is called it attempts to load the requested symbol.
156156
/// If it succeeds, `PTR` is set to the address of that symbol.
157157
/// If it fails, then `PTR` is set to `fallback`.
158-
static PTR: Atomic<*mut c_void> = AtomicPtr::new(load as *mut _);
158+
static PTR: Atomic<*mut c_void> = AtomicPtr::new(load as unsafe extern "system" fn($($argname: $argtype),*) -> $rettype as *mut _);
159159

160160
unsafe extern "system" fn load($($argname: $argtype),*) -> $rettype {
161161
unsafe {
@@ -171,7 +171,7 @@ macro_rules! compat_fn_with_fallback {
171171
PTR.store(f.as_ptr(), Ordering::Relaxed);
172172
mem::transmute(f)
173173
} else {
174-
PTR.store(fallback as *mut _, Ordering::Relaxed);
174+
PTR.store(fallback as unsafe extern "system" fn($($argname: $argtype),*) -> $rettype as *mut _, Ordering::Relaxed);
175175
fallback
176176
}
177177
}

0 commit comments

Comments
 (0)