Skip to content

Commit c14b67f

Browse files
Fix new function_casts_as_integer lint errors in core, std, panic_unwind and compiler crates
f
1 parent 09d48b2 commit c14b67f

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
@@ -152,7 +152,10 @@ fn current_dll_path() -> Result<PathBuf, String> {
152152
unsafe {
153153
GetModuleHandleExW(
154154
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
155-
PCWSTR(current_dll_path as *mut u16),
155+
PCWSTR(
156+
current_dll_path as fn() -> Result<std::path::PathBuf, std::string::String>
157+
as *mut u16,
158+
),
156159
&mut module,
157160
)
158161
}

library/core/src/intrinsics/mod.rs

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

library/panic_unwind/src/seh.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ pub(crate) unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
325325
// In any case, we basically need to do something like this until we can
326326
// express more operations in statics (and we may never be able to).
327327
unsafe {
328+
#[allow(function_casts_as_integer)]
328329
atomic_store_seqcst(
329330
(&raw mut THROW_INFO.pmfnUnwind).cast(),
330331
ptr_t::new(exception_cleanup as *mut u8).raw(),
@@ -341,6 +342,7 @@ pub(crate) unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
341342
(&raw mut CATCHABLE_TYPE.pType).cast(),
342343
ptr_t::new((&raw mut TYPE_DESCRIPTOR).cast()).raw(),
343344
);
345+
#[allow(function_casts_as_integer)]
344346
atomic_store_seqcst(
345347
(&raw mut CATCHABLE_TYPE.copyFunction).cast(),
346348
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
@@ -169,7 +169,9 @@ mod imp {
169169
}
170170

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

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)