Skip to content

library: use core::ffi::c_* types#159868

Draft
xtqqczze wants to merge 1 commit into
rust-lang:mainfrom
xtqqczze:library-ffi
Draft

library: use core::ffi::c_* types#159868
xtqqczze wants to merge 1 commit into
rust-lang:mainfrom
xtqqczze:library-ffi

Conversation

@xtqqczze

Copy link
Copy Markdown
Contributor

No description provided.

@rustbot rustbot added A-compiler-builtins Area: compiler-builtins (https://github.com/rust-lang/compiler-builtins) O-android Operating system: Android O-apple Operating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS) O-fuchsia Operating system: Fuchsia O-hermit Operating System: Hermit O-itron Operating System: ITRON O-linux Operating system: Linux O-netbsd Operating system: NetBSD O-redox Operating system: Redox, https://www.redox-os.org/ O-solaris Operating system: Solaris O-solid Operating System: SOLID O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-windows Operating system: Windows S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 24, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
##[endgroup]
[TIMING:end] tool::ToolBuild { build_compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: x86_64-unknown-linux-gnu, tool: "tidy", path: "src/tools/tidy", mode: ToolBootstrap, source_type: InTree, extra_features: [], allow_features: "", cargo_args: [], artifact_kind: Binary } -- 13.699
[TIMING:end] tool::Tidy { compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: x86_64-unknown-linux-gnu } -- 0.000
fmt check
Diff in /checkout/library/std_detect/src/detect/os/linux/aarch64.rs:13:
         // https://reviews.llvm.org/D114523
         let mut arch = [0_u8; libc::PROP_VALUE_MAX as usize];
         let len = unsafe {
-            libc::__system_property_get(c"ro.arch".as_ptr(), arch.as_mut_ptr() as *mut core::ffi::c_char)
+            libc::__system_property_get(
+                c"ro.arch".as_ptr(),
+                arch.as_mut_ptr() as *mut core::ffi::c_char,
+            )
         };
         // On Exynos, ro.arch is not available on Android 12+, but it is fine
         // because Android 9+ includes the fix.
Diff in /checkout/library/std_detect/src/detect/os/openbsd/auxvec.rs:42:
 
 /// Tries to read the `key` from the auxiliary vector.
 fn archauxv(key: core::ffi::c_int) -> usize {
-    const OUT_LEN: core::ffi::c_int = core::mem::size_of::<core::ffi::c_ulong>() as core::ffi::c_int;
+    const OUT_LEN: core::ffi::c_int =
+        core::mem::size_of::<core::ffi::c_ulong>() as core::ffi::c_int;
     let mut out: core::ffi::c_ulong = 0;
     unsafe {
-        let res =
-            libc::elf_aux_info(key, &mut out as *mut core::ffi::c_ulong as *mut core::ffi::c_void, OUT_LEN);
+        let res = libc::elf_aux_info(
+            key,
+            &mut out as *mut core::ffi::c_ulong as *mut core::ffi::c_void,
+            OUT_LEN,
+        );
         // If elf_aux_info fails, `out` will be left at zero (which is the proper default value).
         debug_assert!(res == 0 || out == 0);
     }
Diff in /checkout/library/std/src/sys/pal/unix/futex.rs:227:
 
 #[cfg(target_os = "emscripten")]
 unsafe extern "C" {
-    fn emscripten_futex_wake(addr: *const Atomic<u32>, count: core::ffi::c_int) -> core::ffi::c_int;
+    fn emscripten_futex_wake(addr: *const Atomic<u32>, count: core::ffi::c_int)
+    -> core::ffi::c_int;
     fn emscripten_futex_wait(
         addr: *const Atomic<u32>,
         val: core::ffi::c_uint,
Diff in /checkout/library/std_detect/src/detect/os/freebsd/auxvec.rs:46:
 
 /// Tries to read the `key` from the auxiliary vector.
 fn archauxv(key: core::ffi::c_int) -> usize {
-    const OUT_LEN: core::ffi::c_int = core::mem::size_of::<core::ffi::c_ulong>() as core::ffi::c_int;
+    const OUT_LEN: core::ffi::c_int =
+        core::mem::size_of::<core::ffi::c_ulong>() as core::ffi::c_int;
     let mut out: core::ffi::c_ulong = 0;
     unsafe {
         // elf_aux_info is available on FreeBSD 12.0+ and 11.4+:
Diff in /checkout/library/std_detect/src/detect/os/freebsd/auxvec.rs:54:
         // https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/sys/auxv.h
         // FreeBSD 11 support in std has been removed in Rust 1.75 (https://github.com/rust-lang/rust/pull/114521),
         // so we can safely use this function.
-        let res =
-            libc::elf_aux_info(key, &mut out as *mut core::ffi::c_ulong as *mut core::ffi::c_void, OUT_LEN);
+        let res = libc::elf_aux_info(
+            key,
+            &mut out as *mut core::ffi::c_ulong as *mut core::ffi::c_void,
+            OUT_LEN,
+        );
         // If elf_aux_info fails, `out` will be left at zero (which is the proper default value).
         debug_assert!(res == 0 || out == 0);
     }
Diff in /checkout/library/std/src/sys/thread_local/destructors/linux_like.rs:40:
     if let Some(f) = unsafe { __cxa_thread_atexit_impl } {
         unsafe {
             f(
-                transmute::<unsafe extern "C" fn(*mut u8), unsafe extern "C" fn(*mut core::ffi::c_void)>(
-                    dtor,
-                ),
+                transmute::<
+                    unsafe extern "C" fn(*mut u8),
+                    unsafe extern "C" fn(*mut core::ffi::c_void),
+                >(dtor),
                 t.cast(),
                 (&raw const __dso_handle) as *mut _,
             );
Diff in /checkout/library/std/src/sys/net/connection/socket/solid.rs:1:
 use core::ffi::{c_int, c_void};
+
 use libc::size_t;
 
 use self::netc::{MSG_PEEK, sockaddr, socklen_t};
Diff in /checkout/library/std/src/sys/net/connection/socket/unix.rs:1:
 use core::ffi::{c_int, c_void};
+
 use libc::{MSG_PEEK, size_t, sockaddr, socklen_t};
 
 #[cfg(not(any(target_os = "espidf", target_os = "nuttx")))]
Diff in /checkout/library/std/src/sys/net/connection/socket/unix.rs:446:
     pub fn set_linger(&self, linger: Option<Duration>) -> io::Result<()> {
         let linger = libc::linger {
             l_onoff: linger.is_some() as core::ffi::c_ushort,
-            l_linger: cmp::min(linger.unwrap_or_default().as_secs(), core::ffi::c_ushort::MAX as u64)
-                as core::ffi::c_ushort,
+            l_linger: cmp::min(
+                linger.unwrap_or_default().as_secs(),
+                core::ffi::c_ushort::MAX as u64,
+            ) as core::ffi::c_ushort,
         };
 
         unsafe { setsockopt(self, libc::SOL_SOCKET, SO_LINGER, linger) }
Diff in /checkout/library/std/src/sys/net/connection/socket/unix.rs:551:
 
     #[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
     pub fn set_passcred(&self, passcred: bool) -> io::Result<()> {
-        unsafe { setsockopt(self, libc::SOL_SOCKET, libc::SO_PASSCRED, passcred as core::ffi::c_int) }
+        unsafe {
+            setsockopt(self, libc::SOL_SOCKET, libc::SO_PASSCRED, passcred as core::ffi::c_int)
+        }
     }
 
     #[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
Diff in /checkout/library/std/src/sys/net/connection/socket/unix.rs:563:
 
     #[cfg(target_os = "netbsd")]
     pub fn set_local_creds(&self, local_creds: bool) -> io::Result<()> {
-        unsafe { setsockopt(self, 0 as core::ffi::c_int, libc::LOCAL_CREDS, local_creds as core::ffi::c_int) }
+        unsafe {
+            setsockopt(
+                self,
+                0 as core::ffi::c_int,
+                libc::LOCAL_CREDS,
---
     #[cfg(target_os = "netbsd")]
Diff in /checkout/library/std/src/sys/pal/solid/abi/fs.rs:1:
 //! `solid_fs.h`
 
+use core::ffi::{c_char, c_int, c_uchar};
+
 pub use libc::{
     O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY, S_IFBLK, S_IFCHR, S_IFDIR,
     S_IFIFO, S_IFMT, S_IFREG, S_IWRITE, SEEK_CUR, SEEK_END, SEEK_SET, ino_t, off_t, stat, time_t,
Diff in /checkout/library/std/src/sys/pal/solid/abi/fs.rs:6:
 };
-
-use core::ffi::{c_char, c_int, c_uchar};
 
 pub const O_ACCMODE: c_int = 0x3;
 
Diff in /checkout/library/std/src/sys/pal/solid/abi/sockets.rs:1:
+use core::ffi::{c_char, c_uint, c_void};
 pub use core::ffi::{c_int, c_long};
-pub use libc::{size_t, ssize_t, timeval};
 
-use core::ffi::{c_char, c_uint, c_void};
+pub use libc::{size_t, ssize_t, timeval};
 
 pub const SOLID_NET_ERR_BASE: c_int = -2000;
 pub const EINPROGRESS: c_int = SOLID_NET_ERR_BASE - libc::EINPROGRESS;
Diff in /checkout/library/std/src/sys/process/unix/unsupported.rs:1:
 use core::ffi::c_int;
+
 use libc::pid_t;
 
 use super::common::*;
Diff in /checkout/library/std/src/sys/process/unix/vxworks.rs:1:
 #![forbid(unsafe_op_in_unsafe_fn)]
 
 use core::ffi::{c_char, c_int};
+
 use libc::{self, RTP_ID};
 
 use super::common::*;
Diff in /checkout/library/std/src/sys/process/unix/fuchsia.rs:1:
 use core::ffi::c_int;
+
 use libc::size_t;
 
 use super::common::*;
Diff in /checkout/library/std/src/sys/process/unix/unix.rs:1:
-#[cfg(target_os = "vxworks")]
-use libc::RTP_ID as pid_t;
 #[cfg(not(target_os = "vxworks"))]
 use core::ffi::c_int;
+
+#[cfg(target_os = "vxworks")]
+use libc::RTP_ID as pid_t;
 #[cfg(not(target_os = "vxworks"))]
 use libc::pid_t;
 #[cfg(not(any(
Diff in /checkout/library/std/src/sys/pal/unix/thread_parking.rs:3:
 #![cfg(target_os = "netbsd")]
 
 use core::ffi::c_long;
+
 use libc::{_lwp_park, _lwp_self, _lwp_unpark, CLOCK_MONOTONIC, lwpid_t, time_t, timespec};
 
 use crate::ptr;
Diff in /checkout/library/std/src/sys/process/unix/common.rs:2:
 mod tests;
 
 use core::ffi::c_int;
+
 use libc::{EXIT_FAILURE, EXIT_SUCCESS, gid_t, pid_t, uid_t};
 
 pub use self::cstring_array::CStringArray;
Diff in /checkout/library/std/src/sys/fs/unix.rs:17:
     target_vendor = "apple",
 ))]
 use core::ffi::c_int;
-use libc::dirfd;
+
 #[cfg(any(target_os = "fuchsia", target_os = "illumos", target_vendor = "apple"))]
 use libc::fstatat as fstatat64;
 #[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "hurd"))]
Diff in /checkout/library/std/src/sys/fs/unix.rs:58:
 use libc::readdir64;
 #[cfg(target_os = "l4re")]
 use libc::readdir64_r;
-use libc::mode_t;
 #[cfg(target_os = "android")]
 use libc::{
     dirent as dirent64, fstat as fstat64, fstatat as fstatat64, ftruncate64, lseek64,
Diff in /checkout/library/std/src/sys/fs/unix.rs:80:
     target_os = "hurd"
 ))]
 use libc::{dirent64, fstat64, ftruncate64, lseek64, lstat64, off64_t, open64, stat64};
+use libc::{dirfd, mode_t};
 
 use crate::ffi::{CStr, OsStr, OsString};
 use crate::fmt::{self, Write as _};
Diff in /checkout/library/std/src/os/solaris/raw.rs:11:
 #![allow(deprecated)]
 
 use core::ffi::c_long;
+
 use crate::os::unix::raw::{gid_t, uid_t};
 
 #[stable(feature = "raw_ext", since = "1.1.0")]
Diff in /checkout/library/std/src/sys/thread/unix.rs:488:
 #[cfg(any(target_os = "solaris", target_os = "illumos", target_os = "nto", target_os = "qnx"))]
 pub fn set_name(name: &CStr) {
     weak!(
-        fn pthread_setname_np(thread: libc::pthread_t, name: *const core::ffi::c_char) -> core::ffi::c_int;
+        fn pthread_setname_np(
+            thread: libc::pthread_t,
+            name: *const core::ffi::c_char,
+        ) -> core::ffi::c_int;
     );
 
     if let Some(f) = pthread_setname_np.get() {
Diff in /checkout/library/std/src/os/haiku/raw.rs:11:
 #![allow(deprecated)]
 
 use core::ffi::c_long;
+
 use crate::os::unix::raw::{gid_t, uid_t};
 
 // Use the direct definition of usize, instead of uintptr_t like in libc
Diff in /checkout/library/std/src/sys/env/unix.rs:1:
-use core::slice::memchr;
-
 use core::ffi::c_char;
+use core::slice::memchr;
 
 pub use super::common::Env;
 use crate::ffi::{CStr, OsStr, OsString};
Diff in /checkout/library/std/src/sys/args/unix.rs:121:
     #[cfg(all(target_os = "linux", target_env = "gnu"))]
     #[used]
     #[unsafe(link_section = ".init_array.00099")]
-    static ARGV_INIT_ARRAY: extern "C" fn(
-        c_int,
-        *const *const u8,
-        *const *const u8,
-    ) = {
-        extern "C" fn init_wrapper(
-            argc: c_int,
-            argv: *const *const u8,
-            _envp: *const *const u8,
-        ) {
+    static ARGV_INIT_ARRAY: extern "C" fn(c_int, *const *const u8, *const *const u8) = {
+        extern "C" fn init_wrapper(argc: c_int, argv: *const *const u8, _envp: *const *const u8) {
             unsafe { really_init(argc as isize, argv) };
         }
         init_wrapper
Diff in /checkout/library/std/src/sys/args/wali.rs:11:
 }
 
 mod imp {
-    use super::Args;
     use core::ffi::{c_uint, c_uint as WaliArgIdx};
+
+    use super::Args;
     use crate::ffi::{CString, OsString};
     use crate::os::unix::prelude::*;
     use crate::sync::OnceLock;
---
 #![allow(deprecated)]
 
 use core::ffi::c_long;
+
 use crate::os::unix::raw::{gid_t, uid_t};
 
 #[stable(feature = "pthread_t", since = "1.8.0")]
Diff in /checkout/library/std/src/os/illumos/raw.rs:9:
 #![allow(deprecated)]
 
 use core::ffi::c_long;
+
 use crate::os::unix::raw::{gid_t, uid_t};
 
 #[stable(feature = "raw_ext", since = "1.1.0")]
Diff in /checkout/library/std/src/os/netbsd/raw.rs:11:
 #![allow(deprecated)]
 
 use core::ffi::c_long;
+
 use crate::os::unix::raw::{gid_t, uid_t};
 
 #[stable(feature = "raw_ext", since = "1.1.0")]
Diff in /checkout/library/std/src/os/android/raw.rs:22:
 #[cfg(any(target_arch = "arm", target_arch = "x86"))]
 mod arch {
     use core::ffi::{c_long, c_longlong, c_uchar, c_uint, c_ulong, c_ulonglong};
+
     use crate::os::unix::raw::{gid_t, uid_t};
 
     #[stable(feature = "raw_ext", since = "1.1.0")]
Diff in /checkout/library/std/src/os/android/raw.rs:92:
 #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
 mod arch {
     use core::ffi::{c_int, c_long, c_uint, c_ulong};
+
     use crate::os::unix::raw::{gid_t, uid_t};
 
     #[stable(feature = "raw_ext", since = "1.1.0")]
Diff in /checkout/library/std/src/os/android/raw.rs:164:
 #[cfg(target_arch = "x86_64")]
 mod arch {
     use core::ffi::{c_long, c_uint, c_ulong};
+
     use crate::os::unix::raw::{gid_t, uid_t};
 
     #[stable(feature = "raw_ext", since = "1.1.0")]
Diff in /checkout/library/std/src/os/motor/ffi.rs:2:
 #![unstable(feature = "motor_ext", issue = "147456")]
 
 use core::ffi::OsStr;
+
 use crate::ffi::OsString;
 use crate::sys::{AsInner, IntoInner};
 
Diff in /checkout/library/std/src/os/espidf/raw.rs:10:
 )]
 
 use core::ffi::c_long;
+
 use crate::os::unix::raw::{gid_t, uid_t};
 
 #[stable(feature = "pthread_t", since = "1.8.0")]
Diff in /checkout/library/alloctests/tests/c_str.rs:1:
-use std::borrow::Cow::{Borrowed, Owned};
 use core::ffi::{CStr, c_char};
+use std::borrow::Cow::{Borrowed, Owned};
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-compiler-builtins Area: compiler-builtins (https://github.com/rust-lang/compiler-builtins) O-android Operating system: Android O-apple Operating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS) O-fuchsia Operating system: Fuchsia O-hermit Operating System: Hermit O-itron Operating System: ITRON O-linux Operating system: Linux O-netbsd Operating system: NetBSD O-redox Operating system: Redox, https://www.redox-os.org/ O-solaris Operating system: Solaris O-solid Operating System: SOLID O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-windows Operating system: Windows S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants