From 65a38a460e0aa377d993862bc529c57d7455098c Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 23 Sep 2025 03:43:43 -0500 Subject: [PATCH 01/12] Update the repr type for C enums Partial cherry pick of 192bccbf2c83 ("ctest: add suport for c enum"). --- src/macros.rs | 34 ++++++++++++++++++---------------- src/types.rs | 8 ++++++++ 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 1bd547f07a28e..76b9f0f4f5dfe 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -87,7 +87,7 @@ macro_rules! prelude { pub(crate) use mem::{align_of, align_of_val, size_of, size_of_val}; #[allow(unused_imports)] - pub(crate) use crate::types::Padding; + pub(crate) use crate::types::{CEnumRepr, Padding}; // Commonly used types defined in this crate #[allow(unused_imports)] pub(crate) use crate::{ @@ -274,9 +274,9 @@ macro_rules! c_enum { c_enum!(@one; $ty_name; $variant + 1; $($tail)*); }; - // Use a specific type if provided, otherwise default to `c_uint` + // Use a specific type if provided, otherwise default to `CEnumRepr` (@ty $repr:ty) => { $repr }; - (@ty) => { $crate::c_uint }; + (@ty) => { $crate::prelude::CEnumRepr }; } // This is a pretty horrible hack to allow us to conditionally mark some functions as 'const', @@ -431,6 +431,8 @@ macro_rules! deprecated_mach { #[cfg(test)] mod tests { + use crate::types::CEnumRepr; + #[test] fn c_enumbasic() { // By default, variants get sequential values. @@ -442,9 +444,9 @@ mod tests { } } - assert_eq!(VAR0, 0_u32); - assert_eq!(VAR1, 1_u32); - assert_eq!(VAR2, 2_u32); + assert_eq!(VAR0, 0 as CEnumRepr); + assert_eq!(VAR1, 1 as CEnumRepr); + assert_eq!(VAR2, 2 as CEnumRepr); } #[test] @@ -471,9 +473,9 @@ mod tests { } } - assert_eq!(VAR2, 2_u32); - assert_eq!(VAR3, 3_u32); - assert_eq!(VAR4, 4_u32); + assert_eq!(VAR2, 2 as CEnumRepr); + assert_eq!(VAR3, 3 as CEnumRepr); + assert_eq!(VAR4, 4 as CEnumRepr); } #[test] @@ -492,12 +494,12 @@ mod tests { } } - assert_eq!(VAR0, 0_u32); - assert_eq!(VAR2_0, 2_u32); - assert_eq!(VAR3_0, 3_u32); - assert_eq!(VAR4_0, 4_u32); - assert_eq!(VAR2_1, 2_u32); - assert_eq!(VAR3_1, 3_u32); - assert_eq!(VAR4_1, 4_u32); + assert_eq!(VAR0, 0 as CEnumRepr); + assert_eq!(VAR2_0, 2 as CEnumRepr); + assert_eq!(VAR3_0, 3 as CEnumRepr); + assert_eq!(VAR4_0, 4 as CEnumRepr); + assert_eq!(VAR2_1, 2 as CEnumRepr); + assert_eq!(VAR3_1, 3 as CEnumRepr); + assert_eq!(VAR4_1, 4 as CEnumRepr); } } diff --git a/src/types.rs b/src/types.rs index d972d2390c9cd..3ef8177c5feca 100644 --- a/src/types.rs +++ b/src/types.rs @@ -16,3 +16,11 @@ impl Default for Padding { Self(MaybeUninit::zeroed()) } } + +/// The default repr type used for C style enums in Rust. +#[cfg(target_env = "msvc")] +#[allow(unused)] +pub(crate) type CEnumRepr = c_int; +#[cfg(not(target_env = "msvc"))] +#[allow(unused)] +pub(crate) type CEnumRepr = c_uint; From 9621d43e3d8462b0a4515dca471ae1c7a5331a03 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sat, 9 Aug 2025 22:58:00 +0000 Subject: [PATCH 02/12] Always implement `Debug` Currently `Debug` implementations are gated behind the `extra-traits` feature. My understanding is that historically, this was for two reasons: 1. `Debug` implementations for unions were unsound 2. Concerns about compile time The first was resolved a while ago by adding a "manual derive" opaque implementation, in 6faa521f32fc ("fix: make Debug impl for unions opaque"). Regarding the second reason, compile times for the current `main` on my machine are (cleaning in between, with the 2025-08-06 nightly): $ cargo build -p libc Compiling libc v1.0.0-alpha.1 (~/rust-libc) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.79s $ cargo build -p libc --release Compiling libc v1.0.0-alpha.1 (~/rust-libc) Finished `release` profile [optimized] target(s) in 0.64s $ cargo build -p libc --features extra_traits Compiling libc v1.0.0-alpha.1 (~/rust-libc) Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.08s $ cargo build -p libc --features extra_traits --release Compiling libc v1.0.0-alpha.1 (~/rust-libc) Finished `release` profile [optimized] target(s) in 0.85s And with this patch applied: $ cargo build -p libc Compiling libc v1.0.0-alpha.1 (~/rust-libc) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.89s $ cargo build -p libc --release Compiling libc v1.0.0-alpha.1 (~/rust-libc) Finished `release` profile [optimized] target(s) in 0.70s $ cargo build -p libc --features extra_traits Compiling libc v1.0.0-alpha.1 (~/rust-libc) Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.15s $ cargo build -p libc --features extra_traits --release Compiling libc v1.0.0-alpha.1 (~/rust-libc) Finished `release` profile [optimized] target(s) in 0.86s That is a microbenchmark but it shows that there probably isn't anything to worry about. Thus, remove the `Debug` implementation from the `feature = "extra_traitts"` gating. Another advantage of doing this is that it should allow many crates to remove the enable for `extra_traits`, giving us a better idea of who wants `Debug` vs. who is actually using the `Eq`/`Hash` implementations. Link: https://github.com/rust-lang/libc/issues/3880 (backport ) (cherry picked from commit a6e75638ce4ea3faa003082fc91226a77336de07) [ needed to apply in a few more places, including the e! macro definition - Trevor ] --- src/fuchsia/mod.rs | 10 ++-- src/lib.rs | 2 - src/macros.rs | 51 ++++++++++++------- src/solid/mod.rs | 4 +- src/unix/aix/powerpc64.rs | 2 +- src/unix/bsd/apple/mod.rs | 8 +-- src/unix/bsd/freebsdlike/dragonfly/mod.rs | 2 +- .../bsd/freebsdlike/freebsd/freebsd11/b32.rs | 3 +- .../bsd/freebsdlike/freebsd/freebsd11/b64.rs | 3 +- src/unix/bsd/freebsdlike/freebsd/mod.rs | 26 ++++++---- src/unix/bsd/freebsdlike/mod.rs | 2 +- src/unix/bsd/netbsdlike/mod.rs | 4 +- src/unix/cygwin/mod.rs | 4 +- src/unix/haiku/mod.rs | 2 +- src/unix/hurd/mod.rs | 4 +- src/unix/linux_like/emscripten/mod.rs | 2 +- src/unix/linux_like/linux/mod.rs | 2 +- src/unix/linux_like/mod.rs | 2 +- src/unix/mod.rs | 6 +-- src/unix/nto/mod.rs | 2 +- src/unix/redox/mod.rs | 2 +- src/unix/solarish/mod.rs | 4 +- src/vxworks/mod.rs | 8 +-- src/wasi/mod.rs | 8 +-- src/windows/mod.rs | 6 +-- 25 files changed, 97 insertions(+), 72 deletions(-) diff --git a/src/fuchsia/mod.rs b/src/fuchsia/mod.rs index 3cd7f7cc31332..6101f06ca2599 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -80,7 +80,7 @@ pub type rlim_t = c_ulonglong; // FIXME(fuchsia): why are these uninhabited types? that seems... wrong? // Presumably these should be `()` or an `extern type` (when that stabilizes). -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum timezone {} impl Copy for timezone {} impl Clone for timezone { @@ -88,7 +88,7 @@ impl Clone for timezone { *self } } -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum DIR {} impl Copy for DIR {} impl Clone for DIR { @@ -97,7 +97,7 @@ impl Clone for DIR { } } -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum fpos64_t {} // FIXME(fuchsia): fill this out with a struct impl Copy for fpos64_t {} impl Clone for fpos64_t { @@ -3421,7 +3421,7 @@ fn __MHDR_END(mhdr: *const msghdr) -> *mut c_uchar { #[link(name = "fdio")] extern "C" {} -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum FILE {} impl Copy for FILE {} impl Clone for FILE { @@ -3429,7 +3429,7 @@ impl Clone for FILE { *self } } -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum fpos_t {} // FIXME(fuchsia): fill this out with a struct impl Copy for fpos_t {} impl Clone for fpos_t { diff --git a/src/lib.rs b/src/lib.rs index 5989c64da6287..39cbbf809f0ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,8 +25,6 @@ #![cfg_attr(feature = "rustc-dep-of-std", allow(internal_features))] // DIFF(1.0): The thread local references that raise this lint were removed in 1.0 #![cfg_attr(feature = "rustc-dep-of-std", allow(static_mut_refs))] -// Enable extra lints: -#![cfg_attr(feature = "extra_traits", warn(missing_debug_implementations))] #![warn(missing_copy_implementations, safe_packed_borrows)] #![cfg_attr(not(feature = "rustc-dep-of-std"), no_std)] #![cfg_attr(feature = "rustc-dep-of-std", no_core)] diff --git a/src/macros.rs b/src/macros.rs index 76b9f0f4f5dfe..1d0672501b9d1 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -72,17 +72,20 @@ macro_rules! prelude { mod prelude { // Exports from `core` #[allow(unused_imports)] - pub(crate) use ::core::clone::Clone; + pub(crate) use core::clone::Clone; #[allow(unused_imports)] - pub(crate) use ::core::default::Default; + pub(crate) use core::default::Default; #[allow(unused_imports)] - pub(crate) use ::core::marker::{Copy, Send, Sync}; + pub(crate) use core::marker::{Copy, Send, Sync}; #[allow(unused_imports)] - pub(crate) use ::core::option::Option; + pub(crate) use core::option::Option; #[allow(unused_imports)] - pub(crate) use ::core::prelude::v1::derive; + pub(crate) use core::prelude::v1::derive; #[allow(unused_imports)] - pub(crate) use ::core::{fmt, hash, iter, mem, ptr}; + pub(crate) use core::{fmt, hash, iter, mem, ptr}; + + #[allow(unused_imports)] + pub(crate) use fmt::Debug; #[allow(unused_imports)] pub(crate) use mem::{align_of, align_of_val, size_of, size_of_val}; @@ -120,9 +123,13 @@ macro_rules! s { #[repr(C)] #[cfg_attr( feature = "extra_traits", - ::core::prelude::v1::derive(Debug, Eq, Hash, PartialEq) + ::core::prelude::v1::derive(Eq, Hash, PartialEq) + )] + #[::core::prelude::v1::derive( + ::core::clone::Clone, + ::core::marker::Copy, + ::core::fmt::Debug, )] - #[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)] #[allow(deprecated)] $(#[$attr])* pub struct $i { $($field)* } @@ -142,17 +149,21 @@ macro_rules! s_paren { __item! { #[cfg_attr( feature = "extra_traits", - ::core::prelude::v1::derive(Debug, Eq, Hash, PartialEq) + ::core::prelude::v1::derive(Eq, Hash, PartialEq) + )] + #[::core::prelude::v1::derive( + ::core::clone::Clone, + ::core::marker::Copy, + ::core::fmt::Debug, )] - #[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)] $(#[$attr])* pub struct $i ( $($field)* ); } )*); } -/// Implement `Clone` and `Copy` for a struct with no `extra_traits` feature, as well as `Debug` -/// with `extra_traits` since that can always be derived. +/// Implement `Clone`, `Copy`, and `Debug` since those can be derived, but exclude `PartialEq`, +/// `Eq`, and `Hash`. /// /// Most items will prefer to use [`s`]. macro_rules! s_no_extra_traits { @@ -171,7 +182,6 @@ macro_rules! s_no_extra_traits { pub union $i { $($field)* } } - #[cfg(feature = "extra_traits")] impl ::core::fmt::Debug for $i { fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { f.debug_struct(::core::stringify!($i)).finish_non_exhaustive() @@ -182,8 +192,11 @@ macro_rules! s_no_extra_traits { (it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => ( __item! { #[repr(C)] - #[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)] - #[cfg_attr(feature = "extra_traits", ::core::prelude::v1::derive(Debug))] + #[::core::prelude::v1::derive( + ::core::clone::Clone, + ::core::marker::Copy, + ::core::fmt::Debug, + )] $(#[$attr])* pub struct $i { $($field)* } } @@ -214,9 +227,13 @@ macro_rules! e { __item! { #[cfg_attr( feature = "extra_traits", - ::core::prelude::v1::derive(Debug, Eq, Hash, PartialEq) + ::core::prelude::v1::derive(Eq, Hash, PartialEq) + )] + #[::core::prelude::v1::derive( + ::core::clone::Clone, + ::core::marker::Copy, + ::core::fmt::Debug, )] - #[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)] $(#[$attr])* pub enum $i { $($field)* } } diff --git a/src/solid/mod.rs b/src/solid/mod.rs index 965c5bb1aa522..40d6a9d348586 100644 --- a/src/solid/mod.rs +++ b/src/solid/mod.rs @@ -395,7 +395,7 @@ pub const SIGUSR1: c_int = 30; pub const SIGUSR2: c_int = 31; pub const SIGPWR: c_int = 32; -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum FILE {} impl Copy for FILE {} impl Clone for FILE { @@ -403,7 +403,7 @@ impl Clone for FILE { *self } } -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum fpos_t {} impl Copy for fpos_t {} impl Clone for fpos_t { diff --git a/src/unix/aix/powerpc64.rs b/src/unix/aix/powerpc64.rs index 856fd0d127d70..ba4ddc057c40b 100644 --- a/src/unix/aix/powerpc64.rs +++ b/src/unix/aix/powerpc64.rs @@ -3,7 +3,7 @@ use crate::prelude::*; // Define lock_data_instrumented as an empty enum missing! { - #[cfg_attr(feature = "extra_traits", derive(Debug))] + #[derive(Debug)] pub enum lock_data_instrumented {} } diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index 0729c0db1e7dd..69720f0ba61fe 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -179,7 +179,7 @@ deprecated_mach! { pub type mach_timebase_info_data_t = mach_timebase_info; } -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum timezone {} impl Copy for timezone {} impl Clone for timezone { @@ -188,7 +188,7 @@ impl Clone for timezone { } } -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] #[repr(u32)] pub enum qos_class_t { QOS_CLASS_USER_INTERACTIVE = 0x21, @@ -205,7 +205,7 @@ impl Clone for qos_class_t { } } -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] #[repr(u32)] pub enum sysdir_search_path_directory_t { SYSDIR_DIRECTORY_APPLICATION = 1, @@ -240,7 +240,7 @@ impl Clone for sysdir_search_path_directory_t { } } -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] #[repr(u32)] pub enum sysdir_search_path_domain_mask_t { SYSDIR_DOMAIN_MASK_USER = (1 << 0), diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs index bf2c06383d92e..d25ae011f6b2d 100644 --- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs @@ -45,7 +45,7 @@ pub type vm_map_entry_t = *mut vm_map_entry; pub type pmap = __c_anonymous_pmap; -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum sem {} impl Copy for sem {} impl Clone for sem { diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd11/b32.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd11/b32.rs index 4b96972433ec9..dca7d6ee79988 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd11/b32.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd11/b32.rs @@ -2,7 +2,8 @@ use crate::off_t; use crate::prelude::*; #[repr(C)] -#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))] +#[derive(Debug)] +#[cfg_attr(feature = "extra_traits", derive(Eq, Hash, PartialEq))] pub struct stat { pub st_dev: crate::dev_t, pub st_ino: crate::ino_t, diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd11/b64.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd11/b64.rs index c492ceb47aa41..1f31aac0e3d3d 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd11/b64.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd11/b64.rs @@ -2,7 +2,8 @@ use crate::off_t; use crate::prelude::*; #[repr(C)] -#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))] +#[derive(Debug)] +#[cfg_attr(feature = "extra_traits", derive(Eq, Hash, PartialEq))] pub struct stat { pub st_dev: crate::dev_t, pub st_ino: crate::ino_t, diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index a23eee3b8bb16..6ae8896063332 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -53,7 +53,8 @@ pub type sctp_assoc_t = u32; pub type eventfd_t = u64; -#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))] +#[derive(Debug)] +#[cfg_attr(feature = "extra_traits", derive(Hash, PartialEq, Eq))] #[repr(u32)] pub enum devstat_support_flags { DEVSTAT_ALL_SUPPORTED = 0x00, @@ -68,7 +69,8 @@ impl Clone for devstat_support_flags { } } -#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))] +#[derive(Debug)] +#[cfg_attr(feature = "extra_traits", derive(Hash, PartialEq, Eq))] #[repr(u32)] pub enum devstat_trans_flags { DEVSTAT_NO_DATA = 0x00, @@ -84,7 +86,8 @@ impl Clone for devstat_trans_flags { } } -#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))] +#[derive(Debug)] +#[cfg_attr(feature = "extra_traits", derive(Hash, PartialEq, Eq))] #[repr(u32)] pub enum devstat_tag_type { DEVSTAT_TAG_SIMPLE = 0x00, @@ -99,7 +102,8 @@ impl Clone for devstat_tag_type { } } -#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))] +#[derive(Debug)] +#[cfg_attr(feature = "extra_traits", derive(Hash, PartialEq, Eq))] #[repr(u32)] pub enum devstat_match_flags { DEVSTAT_MATCH_NONE = 0x00, @@ -114,7 +118,8 @@ impl Clone for devstat_match_flags { } } -#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))] +#[derive(Debug)] +#[cfg_attr(feature = "extra_traits", derive(Hash, PartialEq, Eq))] #[repr(u32)] pub enum devstat_priority { DEVSTAT_PRIORITY_MIN = 0x000, @@ -135,7 +140,8 @@ impl Clone for devstat_priority { } } -#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))] +#[derive(Debug)] +#[cfg_attr(feature = "extra_traits", derive(Hash, PartialEq, Eq))] #[repr(u32)] pub enum devstat_type_flags { DEVSTAT_TYPE_DIRECT = 0x000, @@ -167,7 +173,8 @@ impl Clone for devstat_type_flags { } } -#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))] +#[derive(Debug)] +#[cfg_attr(feature = "extra_traits", derive(Hash, PartialEq, Eq))] #[repr(u32)] pub enum devstat_metric { DSM_NONE, @@ -224,7 +231,8 @@ impl Clone for devstat_metric { } } -#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))] +#[derive(Debug)] +#[cfg_attr(feature = "extra_traits", derive(Hash, PartialEq, Eq))] #[repr(u32)] pub enum devstat_select_mode { DS_SELECT_ADD, @@ -2387,7 +2395,7 @@ cfg_if! { } } -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] #[repr(u32)] pub enum dot3Vendors { dot3VendorAMD = 1, diff --git a/src/unix/bsd/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs index 713f44fabbdd8..ee73397e985e0 100644 --- a/src/unix/bsd/freebsdlike/mod.rs +++ b/src/unix/bsd/freebsdlike/mod.rs @@ -59,7 +59,7 @@ cfg_if! { // link.h -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum timezone {} impl Copy for timezone {} impl Clone for timezone { diff --git a/src/unix/bsd/netbsdlike/mod.rs b/src/unix/bsd/netbsdlike/mod.rs index 8bfeef9d25017..bc3e4cdf094ff 100644 --- a/src/unix/bsd/netbsdlike/mod.rs +++ b/src/unix/bsd/netbsdlike/mod.rs @@ -16,7 +16,7 @@ pub type id_t = u32; pub type sem_t = *mut sem; pub type key_t = c_long; -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum timezone {} impl Copy for timezone {} impl Clone for timezone { @@ -24,7 +24,7 @@ impl Clone for timezone { *self } } -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum sem {} impl Copy for sem {} impl Clone for sem { diff --git a/src/unix/cygwin/mod.rs b/src/unix/cygwin/mod.rs index 4263d92671dd2..cadc2b062bf94 100644 --- a/src/unix/cygwin/mod.rs +++ b/src/unix/cygwin/mod.rs @@ -28,7 +28,7 @@ pub type nlink_t = c_ushort; pub type suseconds_t = c_long; pub type useconds_t = c_ulong; -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum timezone {} impl Copy for timezone {} impl Clone for timezone { @@ -75,7 +75,7 @@ pub type nfds_t = c_uint; pub type sem_t = *mut sem; -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum sem {} impl Copy for sem {} impl Clone for sem { diff --git a/src/unix/haiku/mod.rs b/src/unix/haiku/mod.rs index 6673e96c32971..1ddbaed7e2186 100644 --- a/src/unix/haiku/mod.rs +++ b/src/unix/haiku/mod.rs @@ -80,7 +80,7 @@ pub type ACTION = c_int; pub type posix_spawnattr_t = *mut c_void; pub type posix_spawn_file_actions_t = *mut c_void; -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum timezone {} impl Copy for timezone {} impl Clone for timezone { diff --git a/src/unix/hurd/mod.rs b/src/unix/hurd/mod.rs index a818fc5772cde..16d4c250cc478 100644 --- a/src/unix/hurd/mod.rs +++ b/src/unix/hurd/mod.rs @@ -225,7 +225,7 @@ pub type nl_item = c_int; pub type iconv_t = *mut c_void; -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum fpos64_t {} // FIXME(hurd): fill this out with a struct impl Copy for fpos64_t {} impl Clone for fpos64_t { @@ -234,7 +234,7 @@ impl Clone for fpos64_t { } } -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum timezone {} impl Copy for timezone {} impl Clone for timezone { diff --git a/src/unix/linux_like/emscripten/mod.rs b/src/unix/linux_like/emscripten/mod.rs index 10b0893565a03..811d6aad8519d 100644 --- a/src/unix/linux_like/emscripten/mod.rs +++ b/src/unix/linux_like/emscripten/mod.rs @@ -41,7 +41,7 @@ pub type statfs64 = crate::statfs; pub type statvfs64 = crate::statvfs; pub type dirent64 = crate::dirent; -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum fpos64_t {} // FIXME(emscripten): fill this out with a struct impl Copy for fpos64_t {} impl Clone for fpos64_t { diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 2d236327ea4ef..1df6248e12eb2 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -68,7 +68,7 @@ pub type eventfd_t = u64; cfg_if! { if #[cfg(not(target_env = "gnu"))] { missing! { - #[cfg_attr(feature = "extra_traits", derive(Debug))] + #[derive(Debug)] pub enum fpos64_t {} // FIXME(linux): fill this out with a struct } } diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs index 29f13fb37313e..b0eb9ed85cd13 100644 --- a/src/unix/linux_like/mod.rs +++ b/src/unix/linux_like/mod.rs @@ -9,7 +9,7 @@ pub type key_t = c_int; pub type id_t = c_uint; missing! { - #[cfg_attr(feature = "extra_traits", derive(Debug))] + #[derive(Debug)] pub enum timezone {} } diff --git a/src/unix/mod.rs b/src/unix/mod.rs index b3ac89e9a889e..b59b5bc5ce55f 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -38,7 +38,7 @@ cfg_if! { } missing! { - #[cfg_attr(feature = "extra_traits", derive(Debug))] + #[derive(Debug)] pub enum DIR {} } pub type locale_t = *mut c_void; @@ -568,14 +568,14 @@ cfg_if! { cfg_if! { if #[cfg(not(all(target_os = "linux", target_env = "gnu")))] { missing! { - #[cfg_attr(feature = "extra_traits", derive(Debug))] + #[derive(Debug)] pub enum fpos_t {} // FIXME(unix): fill this out with a struct } } } missing! { - #[cfg_attr(feature = "extra_traits", derive(Debug))] + #[derive(Debug)] pub enum FILE {} } diff --git a/src/unix/nto/mod.rs b/src/unix/nto/mod.rs index c5ebdde3868f3..7baf673394b34 100644 --- a/src/unix/nto/mod.rs +++ b/src/unix/nto/mod.rs @@ -72,7 +72,7 @@ pub type sem_t = sync_t; pub type nl_item = c_int; -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum timezone {} impl Copy for timezone {} impl Clone for timezone { diff --git a/src/unix/redox/mod.rs b/src/unix/redox/mod.rs index 42c534c949fa9..d9ecf1a45a18f 100644 --- a/src/unix/redox/mod.rs +++ b/src/unix/redox/mod.rs @@ -32,7 +32,7 @@ pub type pid_t = usize; pub type uid_t = c_int; pub type gid_t = c_int; -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum timezone {} impl Copy for timezone {} impl Clone for timezone { diff --git a/src/unix/solarish/mod.rs b/src/unix/solarish/mod.rs index fc89d1d6d2a62..a6219a64437f2 100644 --- a/src/unix/solarish/mod.rs +++ b/src/unix/solarish/mod.rs @@ -55,7 +55,7 @@ pub type lgrp_view_t = c_uint; pub type posix_spawnattr_t = *mut c_void; pub type posix_spawn_file_actions_t = *mut c_void; -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum timezone {} impl Copy for timezone {} impl Clone for timezone { @@ -64,7 +64,7 @@ impl Clone for timezone { } } -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum ucred_t {} impl Copy for ucred_t {} impl Clone for ucred_t { diff --git a/src/vxworks/mod.rs b/src/vxworks/mod.rs index b03e8d6112e15..657f85851c8f1 100644 --- a/src/vxworks/mod.rs +++ b/src/vxworks/mod.rs @@ -4,7 +4,7 @@ use core::ptr::null_mut; use crate::prelude::*; -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum DIR {} impl Copy for DIR {} impl Clone for DIR { @@ -95,7 +95,7 @@ pub type sa_family_t = c_uchar; // mqueue.h pub type mqd_t = c_int; -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum _Vx_semaphore {} impl Copy for _Vx_semaphore {} impl Clone for _Vx_semaphore { @@ -1054,7 +1054,7 @@ pub const MAP_CONTIG: c_int = 0x0020; pub const MAP_FAILED: *mut c_void = !0 as *mut c_void; -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum FILE {} impl Copy for FILE {} impl Clone for FILE { @@ -1062,7 +1062,7 @@ impl Clone for FILE { *self } } -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum fpos_t {} // FIXME(vxworks): fill this out with a struct impl Copy for fpos_t {} impl Clone for fpos_t { diff --git a/src/wasi/mod.rs b/src/wasi/mod.rs index 4abb2bc1f99e2..b0ac6b639d0d9 100644 --- a/src/wasi/mod.rs +++ b/src/wasi/mod.rs @@ -42,13 +42,13 @@ s_no_extra_traits! { } #[allow(missing_copy_implementations)] -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum FILE {} #[allow(missing_copy_implementations)] -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum DIR {} #[allow(missing_copy_implementations)] -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum __locale_struct {} s_paren! { @@ -176,7 +176,7 @@ s! { // etc., since it contains a flexible array member with a dynamic size. #[repr(C)] #[allow(missing_copy_implementations)] -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub struct dirent { pub d_ino: ino_t, pub d_type: c_uchar, diff --git a/src/windows/mod.rs b/src/windows/mod.rs index 2703729fac5bf..33ff35ef20a4b 100644 --- a/src/windows/mod.rs +++ b/src/windows/mod.rs @@ -29,7 +29,7 @@ cfg_if! { pub type off_t = i32; pub type dev_t = u32; pub type ino_t = u16; -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum timezone {} impl Copy for timezone {} impl Clone for timezone { @@ -251,7 +251,7 @@ pub const SIG_ACK: crate::sighandler_t = 4; #[link(name = "libcmt", cfg(target_feature = "crt-static"))] extern "C" {} -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum FILE {} impl Copy for FILE {} impl Clone for FILE { @@ -259,7 +259,7 @@ impl Clone for FILE { *self } } -#[cfg_attr(feature = "extra_traits", derive(Debug))] +#[derive(Debug)] pub enum fpos_t {} // FIXME(windows): fill this out with a struct impl Copy for fpos_t {} impl Clone for fpos_t { From afd81c8009548247b791de9d17fc840829f4ae87 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 22 Sep 2025 21:42:25 -0500 Subject: [PATCH 03/12] Implement `Debug` for `Padding` Use the `MaybeUninit` formatting so this prints as `Padding` or similar. (backport ) (cherry picked from commit 4c95aea2add75ffb14c77a9c7475e24636d3b233) --- src/types.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/types.rs b/src/types.rs index 3ef8177c5feca..8be1c2d2e43df 100644 --- a/src/types.rs +++ b/src/types.rs @@ -17,6 +17,16 @@ impl Default for Padding { } } +impl fmt::Debug for Padding { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // Taken frmo `MaybeUninit`'s debug implementation + // NB: there is no `.pad_fmt` so we can't use a simpler `format_args!("Padding<{..}>"). + let full_name = core::any::type_name::(); + let prefix_len = full_name.find("Padding").unwrap(); + f.pad(&full_name[prefix_len..]) + } +} + /// The default repr type used for C style enums in Rust. #[cfg(target_env = "msvc")] #[allow(unused)] From 9f25c7e8d801ea812a63ed2ccd582060a806d11b Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 22 Sep 2025 21:47:24 -0500 Subject: [PATCH 04/12] Add a note about why `Padding` requires `T: Copy` (backport ) (cherry picked from commit cac66e6e250812b4ba48e762aed141588dbe0566) --- src/types.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/types.rs b/src/types.rs index 8be1c2d2e43df..7d49a425d59ea 100644 --- a/src/types.rs +++ b/src/types.rs @@ -6,6 +6,9 @@ use crate::prelude::*; /// A transparent wrapper over `MaybeUninit` to represent uninitialized padding /// while providing `Default`. +// This is restricted to `Copy` types since that's a loose indicator that zeros is actually +// a valid bitpattern. There is no technical reason this is required, though, so it could be +// lifted in the future if it becomes a problem. #[allow(unused)] #[repr(transparent)] #[derive(Clone, Copy)] From 2f7c269f69b1e813054ab585ecb0cd53bc356b66 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 22 Sep 2025 21:59:57 -0500 Subject: [PATCH 05/12] Remove `libc_const_extern_fn` This originally existed for MSRV support, then became a necessary hack to support the old ctest's inability to parse `const fn`. The new ctest doesn't have this limitation, so remove the config. Additionally, switch from the `*` kleene to `?` since that is possible now. (backport ) (cherry picked from commit 48940819fd7ed1797b9cb861c85abdd98c8d3296) --- build.rs | 5 -- src/macros.rs | 144 +++++++++++++------------------------------------- 2 files changed, 38 insertions(+), 111 deletions(-) diff --git a/build.rs b/build.rs index ba1b1df527971..26b2682eb59d4 100644 --- a/build.rs +++ b/build.rs @@ -17,8 +17,6 @@ const ALLOWED_CFGS: &[&str] = &[ "gnu_file_offset_bits64", // Corresponds to `_TIME_BITS=64` in glibc "gnu_time_bits64", - // FIXME(ctest): this config shouldn't be needed but ctest can't parse `const extern fn` - "libc_const_extern_fn", "libc_deny_warnings", "libc_thread_local", "libc_ctest", @@ -151,9 +149,6 @@ fn main() { set_cfg("libc_thread_local"); } - // Set unconditionally when ctest is not being invoked. - set_cfg("libc_const_extern_fn"); - // Since Rust 1.80, configuration that isn't recognized by default needs to be provided to // avoid warnings. if rustc_minor_ver >= 80 { diff --git a/src/macros.rs b/src/macros.rs index 1d0672501b9d1..051f1a13cb53e 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -296,114 +296,46 @@ macro_rules! c_enum { (@ty) => { $crate::prelude::CEnumRepr }; } -// This is a pretty horrible hack to allow us to conditionally mark some functions as 'const', -// without requiring users of this macro to care "libc_const_extern_fn". -// -// When 'libc_const_extern_fn' is enabled, we emit the captured 'const' keyword in the expanded -// function. -// -// When 'libc_const_extern_fn' is disabled, we always emit a plain 'pub unsafe extern fn'. -// Note that the expression matched by the macro is exactly the same - this allows -// users of this macro to work whether or not 'libc_const_extern_fn' is enabled -// -// Unfortunately, we need to duplicate most of this macro between the 'cfg_if' blocks. -// This is because 'const unsafe extern fn' won't even parse on older compilers, -// so we need to avoid emitting it at all of 'libc_const_extern_fn'. -// -// Specifically, moving the 'cfg_if' into the macro body will *not* work. Doing so would cause the -// '#[cfg(libc_const_extern_fn)]' to be emitted into user code. The 'cfg' gate will not stop Rust -// from trying to parse the 'pub const unsafe extern fn', so users would get a compiler error even -// when the 'libc_const_extern_fn' feature is disabled. - -// FIXME(ctest): ctest can't handle `const extern` functions, we should be able to remove this -// cfg completely. -// FIXME(ctest): ctest can't handle `$(,)?` so we use `$(,)*` which isn't quite correct. -cfg_if! { - if #[cfg(libc_const_extern_fn)] { - /// Define an `unsafe` function that is const as long as `libc_const_extern_fn` is enabled. - macro_rules! f { - ($( - $(#[$attr:meta])* - pub $({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty - $body:block - )*) => ($( - #[inline] - $(#[$attr])* - pub $($constness)* unsafe extern "C" fn $i($($arg: $argty),*) -> $ret - $body - )*) - } - - /// Define a safe function that is const as long as `libc_const_extern_fn` is enabled. - macro_rules! safe_f { - ($( - $(#[$attr:meta])* - pub $({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty - $body:block - )*) => ($( - #[inline] - $(#[$attr])* - pub $($constness)* extern "C" fn $i($($arg: $argty),*) -> $ret - $body - )*) - } - - /// A nonpublic function that is const as long as `libc_const_extern_fn` is enabled. - macro_rules! const_fn { - ($( - $(#[$attr:meta])* - $({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty - $body:block - )*) => ($( - #[inline] - $(#[$attr])* - $($constness)* fn $i($($arg: $argty),*) -> $ret - $body - )*) - } - } else { - /// Define an `unsafe` function that is const as long as `libc_const_extern_fn` is enabled. - macro_rules! f { - ($( - $(#[$attr:meta])* - pub $({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty - $body:block - )*) => ($( - #[inline] - $(#[$attr])* - pub unsafe extern "C" fn $i($($arg: $argty),*) -> $ret - $body - )*) - } +/// Define a `unsafe` function. +macro_rules! f { + ($( + $(#[$attr:meta])* + pub $({$constness:ident})? fn $i:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty + $body:block + )*) => ($( + #[inline] + $(#[$attr])* + pub $($constness)? unsafe extern "C" fn $i($($arg: $argty),*) -> $ret + $body + )*) +} - /// Define a safe function that is const as long as `libc_const_extern_fn` is enabled. - macro_rules! safe_f { - ($( - $(#[$attr:meta])* - pub $({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty - $body:block - )*) => ($( - #[inline] - $(#[$attr])* - pub extern "C" fn $i($($arg: $argty),*) -> $ret - $body - )*) - } +/// Define a safe function. +macro_rules! safe_f { + ($( + $(#[$attr:meta])* + pub $({$constness:ident})? fn $i:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty + $body:block + )*) => ($( + #[inline] + $(#[$attr])* + pub $($constness)? extern "C" fn $i($($arg: $argty),*) -> $ret + $body + )*) +} - /// A nonpublic function that is const as long as `libc_const_extern_fn` is enabled. - macro_rules! const_fn { - ($( - $(#[$attr:meta])* - $({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty - $body:block - )*) => ($( - #[inline] - $(#[$attr])* - fn $i($($arg: $argty),*) -> $ret - $body - )*) - } - } +/// Define a nonpublic function. +macro_rules! const_fn { + ($( + $(#[$attr:meta])* + $({$constness:ident})? fn $i:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty + $body:block + )*) => ($( + #[inline] + $(#[$attr])* + $($constness)? fn $i($($arg: $argty),*) -> $ret + $body + )*) } macro_rules! __item { From b5f86758c0f9f48f3c0048d662e75bc5442dcc5a Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 22 Sep 2025 22:40:08 -0500 Subject: [PATCH 06/12] Remove the `libc_ctest` feature This was a workaround for the old ctest not being able to parse something related to the `addr_of!` macros in statics referencing statics. This is not needed with the new ctest; thus, remove the config. (backport ) (cherry picked from commit 4f2c41a5970e13c9c1a7b265583a8dfdbc01b235) --- build.rs | 1 - libc-test/build.rs | 5 ----- src/wasi/mod.rs | 31 +++++++++++-------------------- 3 files changed, 11 insertions(+), 26 deletions(-) diff --git a/build.rs b/build.rs index 26b2682eb59d4..802ea7a37def0 100644 --- a/build.rs +++ b/build.rs @@ -19,7 +19,6 @@ const ALLOWED_CFGS: &[&str] = &[ "gnu_time_bits64", "libc_deny_warnings", "libc_thread_local", - "libc_ctest", // Corresponds to `__USE_TIME_BITS64` in UAPI "linux_time_bits64", "musl_v1_2_3", diff --git a/libc-test/build.rs b/libc-test/build.rs index abf5da9cee334..cc15451b760fb 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1795,11 +1795,6 @@ fn test_wasi(target: &str) { "wchar.h", } - // Currently `ctest2` doesn't support macros-in-static-expressions and will - // panic on them. That affects `CLOCK_*` defines in wasi to set this here - // to omit them. - cfg.cfg("libc_ctest", None); - cfg.rename_struct_ty(move |ty| match ty { "FILE" | "fd_set" | "DIR" => Some(ty.to_string()), t if t.ends_with("_t") => Some(t.to_string()), diff --git a/src/wasi/mod.rs b/src/wasi/mod.rs index b0ac6b639d0d9..823b87aa69efa 100644 --- a/src/wasi/mod.rs +++ b/src/wasi/mod.rs @@ -361,26 +361,17 @@ pub const _SC_PAGE_SIZE: c_int = _SC_PAGESIZE; pub const _SC_IOV_MAX: c_int = 60; pub const _SC_SYMLOOP_MAX: c_int = 173; -cfg_if! { - if #[cfg(libc_ctest)] { - // skip these constants when this is active because `ctest` currently - // panics on parsing the constants below - } else { - // `addr_of!(EXTERN_STATIC)` is now safe; remove `unsafe` when MSRV >= 1.82 - #[allow(unused_unsafe)] - pub static CLOCK_MONOTONIC: clockid_t = - unsafe { clockid_t(core::ptr::addr_of!(_CLOCK_MONOTONIC)) }; - #[allow(unused_unsafe)] - pub static CLOCK_PROCESS_CPUTIME_ID: clockid_t = - unsafe { clockid_t(core::ptr::addr_of!(_CLOCK_PROCESS_CPUTIME_ID)) }; - #[allow(unused_unsafe)] - pub static CLOCK_REALTIME: clockid_t = - unsafe { clockid_t(core::ptr::addr_of!(_CLOCK_REALTIME)) }; - #[allow(unused_unsafe)] - pub static CLOCK_THREAD_CPUTIME_ID: clockid_t = - unsafe { clockid_t(core::ptr::addr_of!(_CLOCK_THREAD_CPUTIME_ID)) }; - } -} +// FIXME(msrv): `addr_of!(EXTERN_STATIC)` is now safe; remove `unsafe` when MSRV >= 1.82 +#[allow(unused_unsafe)] +pub static CLOCK_MONOTONIC: clockid_t = unsafe { clockid_t(core::ptr::addr_of!(_CLOCK_MONOTONIC)) }; +#[allow(unused_unsafe)] +pub static CLOCK_PROCESS_CPUTIME_ID: clockid_t = + unsafe { clockid_t(core::ptr::addr_of!(_CLOCK_PROCESS_CPUTIME_ID)) }; +#[allow(unused_unsafe)] +pub static CLOCK_REALTIME: clockid_t = unsafe { clockid_t(core::ptr::addr_of!(_CLOCK_REALTIME)) }; +#[allow(unused_unsafe)] +pub static CLOCK_THREAD_CPUTIME_ID: clockid_t = + unsafe { clockid_t(core::ptr::addr_of!(_CLOCK_THREAD_CPUTIME_ID)) }; pub const ABDAY_1: crate::nl_item = 0x20000; pub const ABDAY_2: crate::nl_item = 0x20001; From be5538b8aca1eec0087158fd6ea65b8277a5a0e4 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 22 Sep 2025 22:47:46 -0500 Subject: [PATCH 07/12] Resolve a ctest FIXME regarding use of `size_of` in array lengths (backport ) (cherry picked from commit 6f0ebb8f0b6ff8126722bc4b93f339d48573842e) [ note that there was no FIXME comment on 0.2 - Trevor ] --- src/unix/linux_like/linux/musl/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/unix/linux_like/linux/musl/mod.rs b/src/unix/linux_like/linux/musl/mod.rs index f625a3017d832..4bc11449145c7 100644 --- a/src/unix/linux_like/linux/musl/mod.rs +++ b/src/unix/linux_like/linux/musl/mod.rs @@ -136,10 +136,7 @@ s! { pub aio_offset: off_t, __next: *mut c_void, __prev: *mut c_void, - #[cfg(target_pointer_width = "32")] - __dummy4: [c_char; 24], - #[cfg(target_pointer_width = "64")] - __dummy4: [c_char; 16], + __dummy4: [c_char; 32 - 2 * size_of::<*const ()>()], } #[repr(align(8))] From 341fa370e5f62036f1faf360e28668a03dedc7ac Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 22 Sep 2025 22:49:48 -0500 Subject: [PATCH 08/12] doc: Remove an unneeded link to the old ctest repo (backport ) (cherry picked from commit 1880ba50c38c0562af0defe94b0cdb638f7f9dec) --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 74f49f3e7bb04..0cdfaeadf9059 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -89,7 +89,7 @@ standard, it's just a list shared among all OSs that declare `#[cfg(unix)]`. We have two automated tests running on [GitHub Actions](https://github.com/rust-lang/libc/actions): -1. [`libc-test`](https://github.com/gnzlbg/ctest) +1. `libc-test` - `cd libc-test && cargo test` - Use the `skip_*()` functions in `build.rs` if you really need a workaround. 2. Style checker From f96995d884c2cb55c5cb0601b5067eb2c211bddc Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 22 Sep 2025 22:53:44 -0500 Subject: [PATCH 09/12] cleanup: Use `target_vendor = "apple"` The old ctest couldn't handle `target_vendor`, but this is no longer an issue. Simplify the config here. (backport ) (cherry picked from commit 94e3f9805056dca478c6d9dfd25e4333eda5989d) --- src/primitives.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/primitives.rs b/src/primitives.rs index cec4f96f86eed..80a10af4c8546 100644 --- a/src/primitives.rs +++ b/src/primitives.rs @@ -20,14 +20,7 @@ pub type c_double = f64; cfg_if! { if #[cfg(all( not(windows), - // FIXME(ctest): just use `target_vendor` = "apple"` once `ctest` supports it - not(any( - target_os = "macos", - target_os = "ios", - target_os = "tvos", - target_os = "watchos", - target_os = "visionos", - )), + not(target_vendor = "apple"), not(target_os = "vita"), any( target_arch = "aarch64", From b6a3026c7650b1b84cd781957f5bf64dfe89e140 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 22 Sep 2025 22:32:31 -0500 Subject: [PATCH 10/12] cleanup: Simplify the syntax of `f!` and similar macros We no longer need to support gating `const` behind `libc_const_extern_fn`, so remove the awkward `{const}` syntax. (backport ) (cherry picked from commit e860257fc163d58872f0402f333960e19bdcae67) --- ci/style.sh | 7 ---- src/fuchsia/mod.rs | 30 ++++++------- src/macros.rs | 26 +++++++----- src/unix/aix/mod.rs | 26 ++++++------ src/unix/bsd/apple/mod.rs | 22 +++++----- src/unix/bsd/freebsdlike/dragonfly/mod.rs | 14 +++---- .../bsd/freebsdlike/freebsd/freebsd11/mod.rs | 6 +-- .../bsd/freebsdlike/freebsd/freebsd12/mod.rs | 6 +-- .../bsd/freebsdlike/freebsd/freebsd13/mod.rs | 6 +-- .../bsd/freebsdlike/freebsd/freebsd14/mod.rs | 6 +-- .../bsd/freebsdlike/freebsd/freebsd15/mod.rs | 6 +-- src/unix/bsd/freebsdlike/freebsd/mod.rs | 28 ++++++------- src/unix/bsd/freebsdlike/mod.rs | 6 +-- src/unix/bsd/mod.rs | 10 ++--- src/unix/bsd/netbsdlike/netbsd/mod.rs | 20 ++++----- src/unix/bsd/netbsdlike/openbsd/mod.rs | 20 ++++----- src/unix/cygwin/mod.rs | 26 ++++++------ src/unix/haiku/mod.rs | 22 +++++----- src/unix/hurd/mod.rs | 42 +++++++++---------- src/unix/linux_like/android/mod.rs | 6 +-- src/unix/linux_like/emscripten/mod.rs | 6 +-- src/unix/linux_like/linux/mod.rs | 12 +++--- src/unix/linux_like/mod.rs | 38 ++++++++--------- src/unix/mod.rs | 8 ++-- src/unix/newlib/horizon/mod.rs | 16 +++---- src/unix/newlib/rtems/mod.rs | 16 +++---- src/unix/nto/mod.rs | 32 +++++++------- src/unix/redox/mod.rs | 22 +++++----- src/unix/solarish/mod.rs | 26 ++++++------ src/vxworks/mod.rs | 18 ++++---- 30 files changed, 264 insertions(+), 265 deletions(-) diff --git a/ci/style.sh b/ci/style.sh index 2d3e874e38998..200cc15cfa16a 100755 --- a/ci/style.sh +++ b/ci/style.sh @@ -31,12 +31,6 @@ while IFS= read -r file; do # wouldn't be correct for something like `all(any(...), ...)`). perl -pi -0777 -e 's/if #\[cfg\((.*?)\)\]/if cfg_tmp!([$1])/gms' "$file" - # We have some instances of `{const}` that make macros happy but aren't - # valid syntax. Replace this with just the keyword, plus an indicator - # comment on the preceding line (which is where rustfmt puts it. Also - # rust-lang/rustfmt#5464). - perl -pi -e 's/^(\s*)(.*)\{const\}/$1\/\* FMT-CONST \*\/\n$1$2const/g' "$file" - # Format the file. We need to invoke `rustfmt` directly since `cargo fmt` # can't figure out the module tree with the hacks in place. failed=false @@ -45,7 +39,6 @@ while IFS= read -r file; do # Restore all changes to the files. perl -pi -e 's/fn (\w+)_fmt_tmp\(\)/$1!/g' "$file" perl -pi -0777 -e 's/cfg_tmp!\(\[(.*?)\]\)/#[cfg($1)]/gms' "$file" - perl -pi -0777 -e 's/\/\* FMT-CONST \*\/(?:\n\s*)?(.*?)const/$1\{const\}/gms' "$file" # Defer emitting the failure until after the files get reset if [ "$failed" != "false" ]; then diff --git a/src/fuchsia/mod.rs b/src/fuchsia/mod.rs index 6101f06ca2599..31f13b16832d2 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -3326,57 +3326,57 @@ f! { } } - pub {const} fn CMSG_ALIGN(len: size_t) -> size_t { + pub const fn CMSG_ALIGN(len: size_t) -> size_t { (len + size_of::() - 1) & !(size_of::() - 1) } - pub {const} fn CMSG_SPACE(len: c_uint) -> c_uint { + pub const fn CMSG_SPACE(len: c_uint) -> c_uint { (CMSG_ALIGN(len as size_t) + CMSG_ALIGN(size_of::())) as c_uint } - pub {const} fn CMSG_LEN(len: c_uint) -> c_uint { + pub const fn CMSG_LEN(len: c_uint) -> c_uint { (CMSG_ALIGN(size_of::()) + len as size_t) as c_uint } } safe_f! { - pub {const} fn WIFSTOPPED(status: c_int) -> bool { + pub const fn WIFSTOPPED(status: c_int) -> bool { (status & 0xff) == 0x7f } - pub {const} fn WSTOPSIG(status: c_int) -> c_int { + pub const fn WSTOPSIG(status: c_int) -> c_int { (status >> 8) & 0xff } - pub {const} fn WIFCONTINUED(status: c_int) -> bool { + pub const fn WIFCONTINUED(status: c_int) -> bool { status == 0xffff } - pub {const} fn WIFSIGNALED(status: c_int) -> bool { + pub const fn WIFSIGNALED(status: c_int) -> bool { ((status & 0x7f) + 1) as i8 >= 2 } - pub {const} fn WTERMSIG(status: c_int) -> c_int { + pub const fn WTERMSIG(status: c_int) -> c_int { status & 0x7f } - pub {const} fn WIFEXITED(status: c_int) -> bool { + pub const fn WIFEXITED(status: c_int) -> bool { (status & 0x7f) == 0 } - pub {const} fn WEXITSTATUS(status: c_int) -> c_int { + pub const fn WEXITSTATUS(status: c_int) -> c_int { (status >> 8) & 0xff } - pub {const} fn WCOREDUMP(status: c_int) -> bool { + pub const fn WCOREDUMP(status: c_int) -> bool { (status & 0x80) != 0 } - pub {const} fn QCMD(cmd: c_int, type_: c_int) -> c_int { + pub const fn QCMD(cmd: c_int, type_: c_int) -> c_int { (cmd << 8) | (type_ & 0x00ff) } - pub {const} fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { + pub const fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { let major = major as crate::dev_t; let minor = minor as crate::dev_t; let mut dev = 0; @@ -3387,14 +3387,14 @@ safe_f! { dev } - pub {const} fn major(dev: crate::dev_t) -> c_uint { + pub const fn major(dev: crate::dev_t) -> c_uint { let mut major = 0; major |= (dev & 0x00000000000fff00) >> 8; major |= (dev & 0xfffff00000000000) >> 32; major as c_uint } - pub {const} fn minor(dev: crate::dev_t) -> c_uint { + pub const fn minor(dev: crate::dev_t) -> c_uint { let mut minor = 0; minor |= (dev & 0x00000000000000ff) >> 0; minor |= (dev & 0x00000ffffff00000) >> 12; diff --git a/src/macros.rs b/src/macros.rs index 051f1a13cb53e..1ffa71e02df37 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -300,40 +300,46 @@ macro_rules! c_enum { macro_rules! f { ($( $(#[$attr:meta])* - pub $({$constness:ident})? fn $i:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty + // Less than ideal hack to match either `fn` or `const fn`. + pub $(fn $i:ident)? $(const fn $const_i:ident)? + ($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty $body:block - )*) => ($( + )+) => {$( #[inline] $(#[$attr])* - pub $($constness)? unsafe extern "C" fn $i($($arg: $argty),*) -> $ret + pub $(unsafe extern "C" fn $i)? $(const unsafe extern "C" fn $const_i)? + ($($arg: $argty),*) -> $ret $body - )*) + )+}; } /// Define a safe function. macro_rules! safe_f { ($( $(#[$attr:meta])* - pub $({$constness:ident})? fn $i:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty + // Less than ideal hack to match either `fn` or `const fn`. + pub $(fn $i:ident)? $(const fn $const_i:ident)? + ($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty $body:block - )*) => ($( + )+) => {$( #[inline] $(#[$attr])* - pub $($constness)? extern "C" fn $i($($arg: $argty),*) -> $ret + pub $(extern "C" fn $i)? $(const extern "C" fn $const_i)? + ($($arg: $argty),*) -> $ret $body - )*) + )+}; } /// Define a nonpublic function. macro_rules! const_fn { ($( $(#[$attr:meta])* - $({$constness:ident})? fn $i:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty + const fn $i:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty $body:block )*) => ($( #[inline] $(#[$attr])* - $($constness)? fn $i($($arg: $argty),*) -> $ret + const fn $i($($arg: $argty),*) -> $ret $body )*) } diff --git a/src/unix/aix/mod.rs b/src/unix/aix/mod.rs index 8a1b95ea4485d..b6d1af52d133c 100644 --- a/src/unix/aix/mod.rs +++ b/src/unix/aix/mod.rs @@ -2457,11 +2457,11 @@ f! { (cmsg as *mut c_uchar).offset(size_of::() as isize) } - pub {const} fn CMSG_LEN(length: c_uint) -> c_uint { + pub const fn CMSG_LEN(length: c_uint) -> c_uint { size_of::() as c_uint + length } - pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint { + pub const fn CMSG_SPACE(length: c_uint) -> c_uint { size_of::() as c_uint + length } @@ -2493,11 +2493,11 @@ f! { } safe_f! { - pub {const} fn WIFSTOPPED(status: c_int) -> bool { + pub const fn WIFSTOPPED(status: c_int) -> bool { (status & _W_STOPPED) != 0 } - pub {const} fn WSTOPSIG(status: c_int) -> c_int { + pub const fn WSTOPSIG(status: c_int) -> c_int { if WIFSTOPPED(status) { (((status as c_uint) >> 8) & 0xff) as c_int } else { @@ -2505,11 +2505,11 @@ safe_f! { } } - pub {const} fn WIFEXITED(status: c_int) -> bool { + pub const fn WIFEXITED(status: c_int) -> bool { (status & 0xFF) == 0 } - pub {const} fn WEXITSTATUS(status: c_int) -> c_int { + pub const fn WEXITSTATUS(status: c_int) -> c_int { if WIFEXITED(status) { (((status as c_uint) >> 8) & 0xff) as c_int } else { @@ -2517,11 +2517,11 @@ safe_f! { } } - pub {const} fn WIFSIGNALED(status: c_int) -> bool { + pub const fn WIFSIGNALED(status: c_int) -> bool { !WIFEXITED(status) && !WIFSTOPPED(status) } - pub {const} fn WTERMSIG(status: c_int) -> c_int { + pub const fn WTERMSIG(status: c_int) -> c_int { if WIFSIGNALED(status) { (((status as c_uint) >> 16) & 0xff) as c_int } else { @@ -2529,26 +2529,26 @@ safe_f! { } } - pub {const} fn WIFCONTINUED(status: c_int) -> bool { + pub const fn WIFCONTINUED(status: c_int) -> bool { (status & WCONTINUED) != 0 } // AIX doesn't have native WCOREDUMP. - pub {const} fn WCOREDUMP(_status: c_int) -> bool { + pub const fn WCOREDUMP(_status: c_int) -> bool { false } - pub {const} fn major(dev: crate::dev_t) -> c_uint { + pub const fn major(dev: crate::dev_t) -> c_uint { let x = dev >> 16; x as c_uint } - pub {const} fn minor(dev: crate::dev_t) -> c_uint { + pub const fn minor(dev: crate::dev_t) -> c_uint { let y = dev & 0xFFFF; y as c_uint } - pub {const} fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { + pub const fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { let major = major as crate::dev_t; let minor = minor as crate::dev_t; let mut dev = 0; diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index 69720f0ba61fe..1c6e5a8f000f7 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -5214,49 +5214,49 @@ f! { (cmsg as *mut c_uchar).add(__DARWIN_ALIGN32(size_of::())) } - pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint { + pub const fn CMSG_SPACE(length: c_uint) -> c_uint { (__DARWIN_ALIGN32(size_of::()) + __DARWIN_ALIGN32(length as usize)) as c_uint } - pub {const} fn CMSG_LEN(length: c_uint) -> c_uint { + pub const fn CMSG_LEN(length: c_uint) -> c_uint { (__DARWIN_ALIGN32(size_of::()) + length as usize) as c_uint } - pub {const} fn VM_MAKE_TAG(id: u8) -> u32 { + pub const fn VM_MAKE_TAG(id: u8) -> u32 { (id as u32) << 24u32 } } safe_f! { - pub {const} fn WSTOPSIG(status: c_int) -> c_int { + pub const fn WSTOPSIG(status: c_int) -> c_int { status >> 8 } - pub {const} fn _WSTATUS(status: c_int) -> c_int { + pub const fn _WSTATUS(status: c_int) -> c_int { status & 0x7f } - pub {const} fn WIFCONTINUED(status: c_int) -> bool { + pub const fn WIFCONTINUED(status: c_int) -> bool { _WSTATUS(status) == _WSTOPPED && WSTOPSIG(status) == 0x13 } - pub {const} fn WIFSIGNALED(status: c_int) -> bool { + pub const fn WIFSIGNALED(status: c_int) -> bool { _WSTATUS(status) != _WSTOPPED && _WSTATUS(status) != 0 } - pub {const} fn WIFSTOPPED(status: c_int) -> bool { + pub const fn WIFSTOPPED(status: c_int) -> bool { _WSTATUS(status) == _WSTOPPED && WSTOPSIG(status) != 0x13 } - pub {const} fn makedev(major: i32, minor: i32) -> dev_t { + pub const fn makedev(major: i32, minor: i32) -> dev_t { (major << 24) | minor } - pub {const} fn major(dev: dev_t) -> i32 { + pub const fn major(dev: dev_t) -> i32 { (dev >> 24) & 0xff } - pub {const} fn minor(dev: dev_t) -> i32 { + pub const fn minor(dev: dev_t) -> i32 { dev & 0xffffff } } diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs index d25ae011f6b2d..930c7089131f1 100644 --- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs @@ -1420,7 +1420,7 @@ pub const RTAX_MPLS3: c_int = 10; pub const RTAX_MAX: c_int = 11; const_fn! { - {const} fn _CMSG_ALIGN(n: usize) -> usize { + const fn _CMSG_ALIGN(n: usize) -> usize { (n + (size_of::() - 1)) & !(size_of::() - 1) } } @@ -1430,7 +1430,7 @@ f! { (cmsg as *mut c_uchar).offset(_CMSG_ALIGN(size_of::()) as isize) } - pub {const} fn CMSG_LEN(length: c_uint) -> c_uint { + pub const fn CMSG_LEN(length: c_uint) -> c_uint { (_CMSG_ALIGN(size_of::()) + length as usize) as c_uint } @@ -1446,7 +1446,7 @@ f! { } } - pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint { + pub const fn CMSG_SPACE(length: c_uint) -> c_uint { (_CMSG_ALIGN(size_of::()) + _CMSG_ALIGN(length as usize)) as c_uint } @@ -1475,11 +1475,11 @@ f! { } safe_f! { - pub {const} fn WIFSIGNALED(status: c_int) -> bool { + pub const fn WIFSIGNALED(status: c_int) -> bool { (status & 0o177) != 0o177 && (status & 0o177) != 0 } - pub {const} fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { + pub const fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { let major = major as crate::dev_t; let minor = minor as crate::dev_t; let mut dev = 0; @@ -1488,11 +1488,11 @@ safe_f! { dev } - pub {const} fn major(dev: crate::dev_t) -> c_int { + pub const fn major(dev: crate::dev_t) -> c_int { ((dev >> 8) & 0xff) as c_int } - pub {const} fn minor(dev: crate::dev_t) -> c_int { + pub const fn minor(dev: crate::dev_t) -> c_int { (dev & 0xffff00ff) as c_int } } diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs index 64949e5f0daeb..b3b032bc66949 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs @@ -385,17 +385,17 @@ pub const MINCORE_SUPER: c_int = 0x20; pub const SPECNAMELEN: c_int = 63; safe_f! { - pub {const} fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { + pub const fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { let major = major as crate::dev_t; let minor = minor as crate::dev_t; (major << 8) | minor } - pub {const} fn major(dev: crate::dev_t) -> c_int { + pub const fn major(dev: crate::dev_t) -> c_int { ((dev >> 8) & 0xff) as c_int } - pub {const} fn minor(dev: crate::dev_t) -> c_int { + pub const fn minor(dev: crate::dev_t) -> c_int { (dev & 0xffff00ff) as c_int } } diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs index ab7d3fb41317e..962d7817a2649 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs @@ -434,7 +434,7 @@ pub const KI_NSPARE_PTR: usize = 6; pub const MINCORE_SUPER: c_int = 0x20; safe_f! { - pub {const} fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { + pub const fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { let major = major as crate::dev_t; let minor = minor as crate::dev_t; let mut dev = 0; @@ -445,11 +445,11 @@ safe_f! { dev } - pub {const} fn major(dev: crate::dev_t) -> c_int { + pub const fn major(dev: crate::dev_t) -> c_int { (((dev >> 32) & 0xffffff00) | ((dev >> 8) & 0xff)) as c_int } - pub {const} fn minor(dev: crate::dev_t) -> c_int { + pub const fn minor(dev: crate::dev_t) -> c_int { (((dev >> 24) & 0xff00) | (dev & 0xffff00ff)) as c_int } } diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs index ff55933938f54..7b0e467ba375e 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs @@ -456,7 +456,7 @@ pub const DOMAINSET_POLICY_INTERLEAVE: c_int = 4; pub const MINCORE_SUPER: c_int = 0x20; safe_f! { - pub {const} fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { + pub const fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { let major = major as crate::dev_t; let minor = minor as crate::dev_t; let mut dev = 0; @@ -467,11 +467,11 @@ safe_f! { dev } - pub {const} fn major(dev: crate::dev_t) -> c_int { + pub const fn major(dev: crate::dev_t) -> c_int { (((dev >> 32) & 0xffffff00) | ((dev >> 8) & 0xff)) as c_int } - pub {const} fn minor(dev: crate::dev_t) -> c_int { + pub const fn minor(dev: crate::dev_t) -> c_int { (((dev >> 24) & 0xff00) | (dev & 0xffff00ff)) as c_int } } diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs index 3f23f05f5907f..f20a46655665d 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs @@ -458,7 +458,7 @@ pub const DOMAINSET_POLICY_INTERLEAVE: c_int = 4; pub const MINCORE_SUPER: c_int = 0x60; safe_f! { - pub {const} fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { + pub const fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { let major = major as crate::dev_t; let minor = minor as crate::dev_t; let mut dev = 0; @@ -469,11 +469,11 @@ safe_f! { dev } - pub {const} fn major(dev: crate::dev_t) -> c_int { + pub const fn major(dev: crate::dev_t) -> c_int { (((dev >> 32) & 0xffffff00) | ((dev >> 8) & 0xff)) as c_int } - pub {const} fn minor(dev: crate::dev_t) -> c_int { + pub const fn minor(dev: crate::dev_t) -> c_int { (((dev >> 24) & 0xff00) | (dev & 0xffff00ff)) as c_int } } diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd15/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd15/mod.rs index cc8d895331f0c..c0d27ef370e6f 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd15/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd15/mod.rs @@ -460,7 +460,7 @@ pub const DOMAINSET_POLICY_INTERLEAVE: c_int = 4; pub const MINCORE_SUPER: c_int = 0x60; safe_f! { - pub {const} fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { + pub const fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { let major = major as crate::dev_t; let minor = minor as crate::dev_t; let mut dev = 0; @@ -471,11 +471,11 @@ safe_f! { dev } - pub {const} fn major(dev: crate::dev_t) -> c_int { + pub const fn major(dev: crate::dev_t) -> c_int { (((dev >> 32) & 0xffffff00) | ((dev >> 8) & 0xff)) as c_int } - pub {const} fn minor(dev: crate::dev_t) -> c_int { + pub const fn minor(dev: crate::dev_t) -> c_int { (((dev >> 24) & 0xff00) | (dev & 0xffff00ff)) as c_int } } diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index 6ae8896063332..0987617a0f3fc 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -4750,7 +4750,7 @@ pub const fn MAP_ALIGNED(a: c_int) -> c_int { } const_fn! { - {const} fn _ALIGN(p: usize) -> usize { + const fn _ALIGN(p: usize) -> usize { (p + _ALIGNBYTES) & !_ALIGNBYTES } } @@ -4760,7 +4760,7 @@ f! { (cmsg as *mut c_uchar).add(_ALIGN(size_of::())) } - pub {const} fn CMSG_LEN(length: c_uint) -> c_uint { + pub const fn CMSG_LEN(length: c_uint) -> c_uint { _ALIGN(size_of::()) as c_uint + length } @@ -4777,7 +4777,7 @@ f! { } } - pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint { + pub const fn CMSG_SPACE(length: c_uint) -> c_uint { (_ALIGN(size_of::()) + _ALIGN(length as usize)) as c_uint } @@ -4785,11 +4785,11 @@ f! { ffsl(lg as c_long - 1) } - pub {const} fn MALLOCX_TCACHE(tc: c_int) -> c_int { + pub const fn MALLOCX_TCACHE(tc: c_int) -> c_int { (tc + 2) << 8 as c_int } - pub {const} fn MALLOCX_ARENA(a: c_int) -> c_int { + pub const fn MALLOCX_ARENA(a: c_int) -> c_int { (a + 1) << 20 as c_int } @@ -4858,11 +4858,11 @@ f! { } safe_f! { - pub {const} fn WIFSIGNALED(status: c_int) -> bool { + pub const fn WIFSIGNALED(status: c_int) -> bool { (status & 0o177) != 0o177 && (status & 0o177) != 0 && status != 0x13 } - pub {const} fn INVALID_SINFO_FLAG(x: c_int) -> bool { + pub const fn INVALID_SINFO_FLAG(x: c_int) -> bool { (x) & 0xfffffff0 & !(SCTP_EOF | SCTP_ABORT @@ -4874,31 +4874,31 @@ safe_f! { != 0 } - pub {const} fn PR_SCTP_POLICY(x: c_int) -> c_int { + pub const fn PR_SCTP_POLICY(x: c_int) -> c_int { x & 0x0f } - pub {const} fn PR_SCTP_ENABLED(x: c_int) -> bool { + pub const fn PR_SCTP_ENABLED(x: c_int) -> bool { PR_SCTP_POLICY(x) != SCTP_PR_SCTP_NONE && PR_SCTP_POLICY(x) != SCTP_PR_SCTP_ALL } - pub {const} fn PR_SCTP_TTL_ENABLED(x: c_int) -> bool { + pub const fn PR_SCTP_TTL_ENABLED(x: c_int) -> bool { PR_SCTP_POLICY(x) == SCTP_PR_SCTP_TTL } - pub {const} fn PR_SCTP_BUF_ENABLED(x: c_int) -> bool { + pub const fn PR_SCTP_BUF_ENABLED(x: c_int) -> bool { PR_SCTP_POLICY(x) == SCTP_PR_SCTP_BUF } - pub {const} fn PR_SCTP_RTX_ENABLED(x: c_int) -> bool { + pub const fn PR_SCTP_RTX_ENABLED(x: c_int) -> bool { PR_SCTP_POLICY(x) == SCTP_PR_SCTP_RTX } - pub {const} fn PR_SCTP_INVALID_POLICY(x: c_int) -> bool { + pub const fn PR_SCTP_INVALID_POLICY(x: c_int) -> bool { PR_SCTP_POLICY(x) > SCTP_PR_SCTP_MAX } - pub {const} fn PR_SCTP_VALID_POLICY(x: c_int) -> bool { + pub const fn PR_SCTP_VALID_POLICY(x: c_int) -> bool { PR_SCTP_POLICY(x) <= SCTP_PR_SCTP_MAX } } diff --git a/src/unix/bsd/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs index ee73397e985e0..71765b1f3bbf8 100644 --- a/src/unix/bsd/freebsdlike/mod.rs +++ b/src/unix/bsd/freebsdlike/mod.rs @@ -1490,15 +1490,15 @@ pub const POSIX_SPAWN_SETSIGDEF: c_int = 0x10; pub const POSIX_SPAWN_SETSIGMASK: c_int = 0x20; safe_f! { - pub {const} fn WIFCONTINUED(status: c_int) -> bool { + pub const fn WIFCONTINUED(status: c_int) -> bool { status == 0x13 } - pub {const} fn WSTOPSIG(status: c_int) -> c_int { + pub const fn WSTOPSIG(status: c_int) -> c_int { status >> 8 } - pub {const} fn WIFSTOPPED(status: c_int) -> bool { + pub const fn WIFSTOPPED(status: c_int) -> bool { (status & 0o177) == 0o177 } } diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index cb83ccdc7efc0..24531db853145 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -608,23 +608,23 @@ f! { } safe_f! { - pub {const} fn WTERMSIG(status: c_int) -> c_int { + pub const fn WTERMSIG(status: c_int) -> c_int { status & 0o177 } - pub {const} fn WIFEXITED(status: c_int) -> bool { + pub const fn WIFEXITED(status: c_int) -> bool { (status & 0o177) == 0 } - pub {const} fn WEXITSTATUS(status: c_int) -> c_int { + pub const fn WEXITSTATUS(status: c_int) -> c_int { (status >> 8) & 0x00ff } - pub {const} fn WCOREDUMP(status: c_int) -> bool { + pub const fn WCOREDUMP(status: c_int) -> bool { (status & 0o200) != 0 } - pub {const} fn QCMD(cmd: c_int, type_: c_int) -> c_int { + pub const fn QCMD(cmd: c_int, type_: c_int) -> c_int { (cmd << 8) | (type_ & 0x00ff) } } diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 5975cbad4f0ed..bf241a981b8e4 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -2302,7 +2302,7 @@ pub const TFD_TIMER_ABSTIME: i32 = crate::O_WRONLY; pub const TFD_TIMER_CANCEL_ON_SET: i32 = crate::O_RDWR; const_fn! { - {const} fn _ALIGN(p: usize) -> usize { + const fn _ALIGN(p: usize) -> usize { (p + _ALIGNBYTES) & !_ALIGNBYTES } } @@ -2312,7 +2312,7 @@ f! { (cmsg as *mut c_uchar).add(_ALIGN(size_of::())) } - pub {const} fn CMSG_LEN(length: c_uint) -> c_uint { + pub const fn CMSG_LEN(length: c_uint) -> c_uint { _ALIGN(size_of::()) as c_uint + length } @@ -2329,7 +2329,7 @@ f! { } } - pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint { + pub const fn CMSG_SPACE(length: c_uint) -> c_uint { (_ALIGN(size_of::()) + _ALIGN(length as usize)) as c_uint } @@ -2355,23 +2355,23 @@ f! { } safe_f! { - pub {const} fn WSTOPSIG(status: c_int) -> c_int { + pub const fn WSTOPSIG(status: c_int) -> c_int { status >> 8 } - pub {const} fn WIFSIGNALED(status: c_int) -> bool { + pub const fn WIFSIGNALED(status: c_int) -> bool { (status & 0o177) != 0o177 && (status & 0o177) != 0 } - pub {const} fn WIFSTOPPED(status: c_int) -> bool { + pub const fn WIFSTOPPED(status: c_int) -> bool { (status & 0o177) == 0o177 } - pub {const} fn WIFCONTINUED(status: c_int) -> bool { + pub const fn WIFCONTINUED(status: c_int) -> bool { status == 0xffff } - pub {const} fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { + pub const fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { let major = major as crate::dev_t; let minor = minor as crate::dev_t; let mut dev = 0; @@ -2381,11 +2381,11 @@ safe_f! { dev } - pub {const} fn major(dev: crate::dev_t) -> c_int { + pub const fn major(dev: crate::dev_t) -> c_int { (((dev as u32) & 0x000fff00) >> 8) as c_int } - pub {const} fn minor(dev: crate::dev_t) -> c_int { + pub const fn minor(dev: crate::dev_t) -> c_int { let mut res = 0; res |= ((dev as u32) & 0xfff00000) >> 12; res |= (dev as u32) & 0x000000ff; diff --git a/src/unix/bsd/netbsdlike/openbsd/mod.rs b/src/unix/bsd/netbsdlike/openbsd/mod.rs index 74648feff585d..5a5307c499166 100644 --- a/src/unix/bsd/netbsdlike/openbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/openbsd/mod.rs @@ -1869,7 +1869,7 @@ pub const RTAX_SEARCH: c_int = 14; pub const RTAX_MAX: c_int = 15; const_fn! { - {const} fn _ALIGN(p: usize) -> usize { + const fn _ALIGN(p: usize) -> usize { (p + _ALIGNBYTES) & !_ALIGNBYTES } } @@ -1879,7 +1879,7 @@ f! { (cmsg as *mut c_uchar).offset(_ALIGN(size_of::()) as isize) } - pub {const} fn CMSG_LEN(length: c_uint) -> c_uint { + pub const fn CMSG_LEN(length: c_uint) -> c_uint { _ALIGN(size_of::()) as c_uint + length } @@ -1896,29 +1896,29 @@ f! { } } - pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint { + pub const fn CMSG_SPACE(length: c_uint) -> c_uint { (_ALIGN(size_of::()) + _ALIGN(length as usize)) as c_uint } } safe_f! { - pub {const} fn WSTOPSIG(status: c_int) -> c_int { + pub const fn WSTOPSIG(status: c_int) -> c_int { status >> 8 } - pub {const} fn WIFSIGNALED(status: c_int) -> bool { + pub const fn WIFSIGNALED(status: c_int) -> bool { (status & 0o177) != 0o177 && (status & 0o177) != 0 } - pub {const} fn WIFSTOPPED(status: c_int) -> bool { + pub const fn WIFSTOPPED(status: c_int) -> bool { (status & 0xff) == 0o177 } - pub {const} fn WIFCONTINUED(status: c_int) -> bool { + pub const fn WIFCONTINUED(status: c_int) -> bool { (status & 0o177777) == 0o177777 } - pub {const} fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { + pub const fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { let major = major as crate::dev_t; let minor = minor as crate::dev_t; let mut dev = 0; @@ -1928,11 +1928,11 @@ safe_f! { dev } - pub {const} fn major(dev: crate::dev_t) -> c_uint { + pub const fn major(dev: crate::dev_t) -> c_uint { ((dev as c_uint) >> 8) & 0xff } - pub {const} fn minor(dev: crate::dev_t) -> c_uint { + pub const fn minor(dev: crate::dev_t) -> c_uint { let dev = dev as c_uint; let mut res = 0; res |= (dev) & 0xff; diff --git a/src/unix/cygwin/mod.rs b/src/unix/cygwin/mod.rs index cadc2b062bf94..6d94a00ddb25a 100644 --- a/src/unix/cygwin/mod.rs +++ b/src/unix/cygwin/mod.rs @@ -1853,7 +1853,7 @@ f! { CMSG_ALIGN(size_of::()) as c_uint + length } - pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint { + pub const fn CMSG_SPACE(length: c_uint) -> c_uint { (CMSG_ALIGN(length as usize) + CMSG_ALIGN(size_of::())) as c_uint } @@ -1881,55 +1881,55 @@ f! { } safe_f! { - pub {const} fn makedev(ma: c_uint, mi: c_uint) -> dev_t { + pub const fn makedev(ma: c_uint, mi: c_uint) -> dev_t { let ma = ma as dev_t; let mi = mi as dev_t; (ma << 16) | (mi & 0xffff) } - pub {const} fn major(dev: dev_t) -> c_uint { + pub const fn major(dev: dev_t) -> c_uint { ((dev >> 16) & 0xffff) as c_uint } - pub {const} fn minor(dev: dev_t) -> c_uint { + pub const fn minor(dev: dev_t) -> c_uint { (dev & 0xffff) as c_uint } - pub {const} fn WIFEXITED(status: c_int) -> bool { + pub const fn WIFEXITED(status: c_int) -> bool { (status & 0xff) == 0 } - pub {const} fn WIFSIGNALED(status: c_int) -> bool { + pub const fn WIFSIGNALED(status: c_int) -> bool { (status & 0o177) != 0o177 && (status & 0o177) != 0 } - pub {const} fn WIFSTOPPED(status: c_int) -> bool { + pub const fn WIFSTOPPED(status: c_int) -> bool { (status & 0xff) == 0o177 } - pub {const} fn WIFCONTINUED(status: c_int) -> bool { + pub const fn WIFCONTINUED(status: c_int) -> bool { (status & 0o177777) == 0o177777 } - pub {const} fn WEXITSTATUS(status: c_int) -> c_int { + pub const fn WEXITSTATUS(status: c_int) -> c_int { (status >> 8) & 0xff } - pub {const} fn WTERMSIG(status: c_int) -> c_int { + pub const fn WTERMSIG(status: c_int) -> c_int { status & 0o177 } - pub {const} fn WSTOPSIG(status: c_int) -> c_int { + pub const fn WSTOPSIG(status: c_int) -> c_int { (status >> 8) & 0xff } - pub {const} fn WCOREDUMP(status: c_int) -> bool { + pub const fn WCOREDUMP(status: c_int) -> bool { WIFSIGNALED(status) && (status & 0x80) != 0 } } const_fn! { - {const} fn CMSG_ALIGN(len: usize) -> usize { + const fn CMSG_ALIGN(len: usize) -> usize { len + size_of::() - 1 & !(size_of::() - 1) } } diff --git a/src/unix/haiku/mod.rs b/src/unix/haiku/mod.rs index 1ddbaed7e2186..e1b31b32338f7 100644 --- a/src/unix/haiku/mod.rs +++ b/src/unix/haiku/mod.rs @@ -1515,7 +1515,7 @@ pub const POSIX_SPAWN_SETSIGMASK: c_int = 0x20; pub const POSIX_SPAWN_SETSID: c_int = 0x40; const_fn! { - {const} fn CMSG_ALIGN(len: usize) -> usize { + const fn CMSG_ALIGN(len: usize) -> usize { len + size_of::() - 1 & !(size_of::() - 1) } } @@ -1533,11 +1533,11 @@ f! { (cmsg as *mut c_uchar).offset(CMSG_ALIGN(size_of::()) as isize) } - pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint { + pub const fn CMSG_SPACE(length: c_uint) -> c_uint { (CMSG_ALIGN(length as usize) + CMSG_ALIGN(size_of::())) as c_uint } - pub {const} fn CMSG_LEN(length: c_uint) -> c_uint { + pub const fn CMSG_LEN(length: c_uint) -> c_uint { CMSG_ALIGN(size_of::()) as c_uint + length } @@ -1584,36 +1584,36 @@ f! { } safe_f! { - pub {const} fn WIFEXITED(status: c_int) -> bool { + pub const fn WIFEXITED(status: c_int) -> bool { (status & !0xff) == 0 } - pub {const} fn WEXITSTATUS(status: c_int) -> c_int { + pub const fn WEXITSTATUS(status: c_int) -> c_int { status & 0xff } - pub {const} fn WIFSIGNALED(status: c_int) -> bool { + pub const fn WIFSIGNALED(status: c_int) -> bool { ((status >> 8) & 0xff) != 0 } - pub {const} fn WTERMSIG(status: c_int) -> c_int { + pub const fn WTERMSIG(status: c_int) -> c_int { (status >> 8) & 0xff } - pub {const} fn WIFSTOPPED(status: c_int) -> bool { + pub const fn WIFSTOPPED(status: c_int) -> bool { ((status >> 16) & 0xff) != 0 } - pub {const} fn WSTOPSIG(status: c_int) -> c_int { + pub const fn WSTOPSIG(status: c_int) -> c_int { (status >> 16) & 0xff } // actually WIFCORED, but this is used everywhere else - pub {const} fn WCOREDUMP(status: c_int) -> bool { + pub const fn WCOREDUMP(status: c_int) -> bool { (status & 0x10000) != 0 } - pub {const} fn WIFCONTINUED(status: c_int) -> bool { + pub const fn WIFCONTINUED(status: c_int) -> bool { (status & 0x20000) != 0 } } diff --git a/src/unix/hurd/mod.rs b/src/unix/hurd/mod.rs index 16d4c250cc478..5d63937a97fc7 100644 --- a/src/unix/hurd/mod.rs +++ b/src/unix/hurd/mod.rs @@ -3415,7 +3415,7 @@ pub const PTHREAD_STACK_MIN: size_t = 0; const _UTSNAME_LENGTH: usize = 1024; const_fn! { - {const} fn CMSG_ALIGN(len: usize) -> usize { + const fn CMSG_ALIGN(len: usize) -> usize { (len + size_of::() - 1) & !(size_of::() - 1) } } @@ -3434,11 +3434,11 @@ f! { (cmsg as *mut c_uchar).offset(CMSG_ALIGN(size_of::()) as isize) } - pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint { + pub const fn CMSG_SPACE(length: c_uint) -> c_uint { (CMSG_ALIGN(length as usize) + CMSG_ALIGN(size_of::())) as c_uint } - pub {const} fn CMSG_LEN(length: c_uint) -> c_uint { + pub const fn CMSG_LEN(length: c_uint) -> c_uint { CMSG_ALIGN(size_of::()) as c_uint + length } @@ -4528,7 +4528,7 @@ extern "C" { } safe_f! { - pub {const} fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { + pub const fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { let major = major as crate::dev_t; let minor = minor as crate::dev_t; let mut dev = 0; @@ -4537,11 +4537,11 @@ safe_f! { dev } - pub {const} fn major(dev: crate::dev_t) -> c_uint { + pub const fn major(dev: crate::dev_t) -> c_uint { ((dev >> 8) & 0xff) as c_uint } - pub {const} fn minor(dev: crate::dev_t) -> c_uint { + pub const fn minor(dev: crate::dev_t) -> c_uint { (dev & 0xffff00ff) as c_uint } @@ -4553,63 +4553,63 @@ safe_f! { unsafe { __libc_current_sigrtmin() } } - pub {const} fn WIFSTOPPED(status: c_int) -> bool { + pub const fn WIFSTOPPED(status: c_int) -> bool { (status & 0xff) == 0x7f } - pub {const} fn WSTOPSIG(status: c_int) -> c_int { + pub const fn WSTOPSIG(status: c_int) -> c_int { (status >> 8) & 0xff } - pub {const} fn WIFCONTINUED(status: c_int) -> bool { + pub const fn WIFCONTINUED(status: c_int) -> bool { status == 0xffff } - pub {const} fn WIFSIGNALED(status: c_int) -> bool { + pub const fn WIFSIGNALED(status: c_int) -> bool { ((status & 0x7f) + 1) as i8 >= 2 } - pub {const} fn WTERMSIG(status: c_int) -> c_int { + pub const fn WTERMSIG(status: c_int) -> c_int { status & 0x7f } - pub {const} fn WIFEXITED(status: c_int) -> bool { + pub const fn WIFEXITED(status: c_int) -> bool { (status & 0x7f) == 0 } - pub {const} fn WEXITSTATUS(status: c_int) -> c_int { + pub const fn WEXITSTATUS(status: c_int) -> c_int { (status >> 8) & 0xff } - pub {const} fn WCOREDUMP(status: c_int) -> bool { + pub const fn WCOREDUMP(status: c_int) -> bool { (status & 0x80) != 0 } - pub {const} fn W_EXITCODE(ret: c_int, sig: c_int) -> c_int { + pub const fn W_EXITCODE(ret: c_int, sig: c_int) -> c_int { (ret << 8) | sig } - pub {const} fn W_STOPCODE(sig: c_int) -> c_int { + pub const fn W_STOPCODE(sig: c_int) -> c_int { (sig << 8) | 0x7f } - pub {const} fn QCMD(cmd: c_int, type_: c_int) -> c_int { + pub const fn QCMD(cmd: c_int, type_: c_int) -> c_int { (cmd << 8) | (type_ & 0x00ff) } - pub {const} fn IPOPT_COPIED(o: u8) -> u8 { + pub const fn IPOPT_COPIED(o: u8) -> u8 { o & IPOPT_COPY } - pub {const} fn IPOPT_CLASS(o: u8) -> u8 { + pub const fn IPOPT_CLASS(o: u8) -> u8 { o & IPOPT_CLASS_MASK } - pub {const} fn IPOPT_NUMBER(o: u8) -> u8 { + pub const fn IPOPT_NUMBER(o: u8) -> u8 { o & IPOPT_NUMBER_MASK } - pub {const} fn IPTOS_ECN(x: u8) -> u8 { + pub const fn IPTOS_ECN(x: u8) -> u8 { x & crate::IPTOS_ECN_MASK } } diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index bb08e9ab5f420..fbd8ac2f87cfc 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -3596,17 +3596,17 @@ f! { } safe_f! { - pub {const} fn makedev(ma: c_uint, mi: c_uint) -> crate::dev_t { + pub const fn makedev(ma: c_uint, mi: c_uint) -> crate::dev_t { let ma = ma as crate::dev_t; let mi = mi as crate::dev_t; ((ma & 0xfff) << 8) | (mi & 0xff) | ((mi & 0xfff00) << 12) } - pub {const} fn major(dev: crate::dev_t) -> c_int { + pub const fn major(dev: crate::dev_t) -> c_int { ((dev >> 8) & 0xfff) as c_int } - pub {const} fn minor(dev: crate::dev_t) -> c_int { + pub const fn minor(dev: crate::dev_t) -> c_int { ((dev & 0xff) | ((dev >> 12) & 0xfff00)) as c_int } } diff --git a/src/unix/linux_like/emscripten/mod.rs b/src/unix/linux_like/emscripten/mod.rs index 811d6aad8519d..417e3e593bc5e 100644 --- a/src/unix/linux_like/emscripten/mod.rs +++ b/src/unix/linux_like/emscripten/mod.rs @@ -1407,7 +1407,7 @@ f! { } safe_f! { - pub {const} fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { + pub const fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { let major = major as crate::dev_t; let minor = minor as crate::dev_t; let mut dev = 0; @@ -1418,7 +1418,7 @@ safe_f! { dev } - pub {const} fn major(dev: crate::dev_t) -> c_uint { + pub const fn major(dev: crate::dev_t) -> c_uint { // see // https://github.com/emscripten-core/emscripten/blob/ // main/system/lib/libc/musl/include/sys/sysmacros.h @@ -1428,7 +1428,7 @@ safe_f! { major as c_uint } - pub {const} fn minor(dev: crate::dev_t) -> c_uint { + pub const fn minor(dev: crate::dev_t) -> c_uint { // see // https://github.com/emscripten-core/emscripten/blob/ // main/system/lib/libc/musl/include/sys/sysmacros.h diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 1df6248e12eb2..14401077479ed 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -5945,7 +5945,7 @@ f! { } safe_f! { - pub {const} fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { + pub const fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { let major = major as crate::dev_t; let minor = minor as crate::dev_t; let mut dev = 0; @@ -5956,29 +5956,29 @@ safe_f! { dev } - pub {const} fn major(dev: crate::dev_t) -> c_uint { + pub const fn major(dev: crate::dev_t) -> c_uint { let mut major = 0; major |= (dev & 0x00000000000fff00) >> 8; major |= (dev & 0xfffff00000000000) >> 32; major as c_uint } - pub {const} fn minor(dev: crate::dev_t) -> c_uint { + pub const fn minor(dev: crate::dev_t) -> c_uint { let mut minor = 0; minor |= (dev & 0x00000000000000ff) >> 0; minor |= (dev & 0x00000ffffff00000) >> 12; minor as c_uint } - pub {const} fn SCTP_PR_TTL_ENABLED(policy: c_int) -> bool { + pub const fn SCTP_PR_TTL_ENABLED(policy: c_int) -> bool { policy == SCTP_PR_SCTP_TTL } - pub {const} fn SCTP_PR_RTX_ENABLED(policy: c_int) -> bool { + pub const fn SCTP_PR_RTX_ENABLED(policy: c_int) -> bool { policy == SCTP_PR_SCTP_RTX } - pub {const} fn SCTP_PR_PRIO_ENABLED(policy: c_int) -> bool { + pub const fn SCTP_PR_PRIO_ENABLED(policy: c_int) -> bool { policy == SCTP_PR_SCTP_PRIO } } diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs index b0eb9ed85cd13..2f7661d25105d 100644 --- a/src/unix/linux_like/mod.rs +++ b/src/unix/linux_like/mod.rs @@ -1785,7 +1785,7 @@ cfg_if! { } const_fn! { - {const} fn CMSG_ALIGN(len: usize) -> usize { + const fn CMSG_ALIGN(len: usize) -> usize { (len + size_of::() - 1) & !(size_of::() - 1) } } @@ -1803,11 +1803,11 @@ f! { cmsg.offset(1) as *mut c_uchar } - pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint { + pub const fn CMSG_SPACE(length: c_uint) -> c_uint { (CMSG_ALIGN(length as usize) + CMSG_ALIGN(size_of::())) as c_uint } - pub {const} fn CMSG_LEN(length: c_uint) -> c_uint { + pub const fn CMSG_LEN(length: c_uint) -> c_uint { CMSG_ALIGN(size_of::()) as c_uint + length } @@ -1847,68 +1847,68 @@ safe_f! { unsafe { __libc_current_sigrtmin() } } - pub {const} fn WIFSTOPPED(status: c_int) -> bool { + pub const fn WIFSTOPPED(status: c_int) -> bool { (status & 0xff) == 0x7f } - pub {const} fn WSTOPSIG(status: c_int) -> c_int { + pub const fn WSTOPSIG(status: c_int) -> c_int { (status >> 8) & 0xff } - pub {const} fn WIFCONTINUED(status: c_int) -> bool { + pub const fn WIFCONTINUED(status: c_int) -> bool { status == 0xffff } - pub {const} fn WIFSIGNALED(status: c_int) -> bool { + pub const fn WIFSIGNALED(status: c_int) -> bool { ((status & 0x7f) + 1) as i8 >= 2 } - pub {const} fn WTERMSIG(status: c_int) -> c_int { + pub const fn WTERMSIG(status: c_int) -> c_int { status & 0x7f } - pub {const} fn WIFEXITED(status: c_int) -> bool { + pub const fn WIFEXITED(status: c_int) -> bool { (status & 0x7f) == 0 } - pub {const} fn WEXITSTATUS(status: c_int) -> c_int { + pub const fn WEXITSTATUS(status: c_int) -> c_int { (status >> 8) & 0xff } - pub {const} fn WCOREDUMP(status: c_int) -> bool { + pub const fn WCOREDUMP(status: c_int) -> bool { (status & 0x80) != 0 } - pub {const} fn W_EXITCODE(ret: c_int, sig: c_int) -> c_int { + pub const fn W_EXITCODE(ret: c_int, sig: c_int) -> c_int { (ret << 8) | sig } - pub {const} fn W_STOPCODE(sig: c_int) -> c_int { + pub const fn W_STOPCODE(sig: c_int) -> c_int { (sig << 8) | 0x7f } - pub {const} fn QCMD(cmd: c_int, type_: c_int) -> c_int { + pub const fn QCMD(cmd: c_int, type_: c_int) -> c_int { (cmd << 8) | (type_ & 0x00ff) } - pub {const} fn IPOPT_COPIED(o: u8) -> u8 { + pub const fn IPOPT_COPIED(o: u8) -> u8 { o & IPOPT_COPY } - pub {const} fn IPOPT_CLASS(o: u8) -> u8 { + pub const fn IPOPT_CLASS(o: u8) -> u8 { o & IPOPT_CLASS_MASK } - pub {const} fn IPOPT_NUMBER(o: u8) -> u8 { + pub const fn IPOPT_NUMBER(o: u8) -> u8 { o & IPOPT_NUMBER_MASK } - pub {const} fn IPTOS_ECN(x: u8) -> u8 { + pub const fn IPTOS_ECN(x: u8) -> u8 { x & crate::IPTOS_ECN_MASK } #[allow(ellipsis_inclusive_range_patterns)] - pub {const} fn KERNEL_VERSION(a: u32, b: u32, c: u32) -> u32 { + pub const fn KERNEL_VERSION(a: u32, b: u32, c: u32) -> u32 { ((a << 16) + (b << 8)) + if c > 255 { 255 } else { c } } } diff --git a/src/unix/mod.rs b/src/unix/mod.rs index b59b5bc5ce55f..6ba5d87de7ca0 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -1614,16 +1614,16 @@ extern "C" { safe_f! { // It seems htonl, etc are macros on macOS. So we have to reimplement them. So let's // reimplement them for all UNIX platforms - pub {const} fn htonl(hostlong: u32) -> u32 { + pub const fn htonl(hostlong: u32) -> u32 { u32::to_be(hostlong) } - pub {const} fn htons(hostshort: u16) -> u16 { + pub const fn htons(hostshort: u16) -> u16 { u16::to_be(hostshort) } - pub {const} fn ntohl(netlong: u32) -> u32 { + pub const fn ntohl(netlong: u32) -> u32 { u32::from_be(netlong) } - pub {const} fn ntohs(netshort: u16) -> u16 { + pub const fn ntohs(netshort: u16) -> u16 { u16::from_be(netshort) } } diff --git a/src/unix/newlib/horizon/mod.rs b/src/unix/newlib/horizon/mod.rs index ee325a0247241..3958e02734ada 100644 --- a/src/unix/newlib/horizon/mod.rs +++ b/src/unix/newlib/horizon/mod.rs @@ -185,35 +185,35 @@ pub const GRND_RANDOM: c_uint = 0x2; // Horizon OS works doesn't or can't hold any of this information safe_f! { - pub {const} fn WIFSTOPPED(_status: c_int) -> bool { + pub const fn WIFSTOPPED(_status: c_int) -> bool { false } - pub {const} fn WSTOPSIG(_status: c_int) -> c_int { + pub const fn WSTOPSIG(_status: c_int) -> c_int { 0 } - pub {const} fn WIFCONTINUED(_status: c_int) -> bool { + pub const fn WIFCONTINUED(_status: c_int) -> bool { true } - pub {const} fn WIFSIGNALED(_status: c_int) -> bool { + pub const fn WIFSIGNALED(_status: c_int) -> bool { false } - pub {const} fn WTERMSIG(_status: c_int) -> c_int { + pub const fn WTERMSIG(_status: c_int) -> c_int { 0 } - pub {const} fn WIFEXITED(_status: c_int) -> bool { + pub const fn WIFEXITED(_status: c_int) -> bool { true } - pub {const} fn WEXITSTATUS(_status: c_int) -> c_int { + pub const fn WEXITSTATUS(_status: c_int) -> c_int { 0 } - pub {const} fn WCOREDUMP(_status: c_int) -> bool { + pub const fn WCOREDUMP(_status: c_int) -> bool { false } } diff --git a/src/unix/newlib/rtems/mod.rs b/src/unix/newlib/rtems/mod.rs index f14967da0aad1..0e23352744149 100644 --- a/src/unix/newlib/rtems/mod.rs +++ b/src/unix/newlib/rtems/mod.rs @@ -85,38 +85,38 @@ pub const WUNTRACED: c_int = 2; pub const SOMAXCONN: c_int = 128; safe_f! { - pub {const} fn WIFSTOPPED(status: c_int) -> bool { + pub const fn WIFSTOPPED(status: c_int) -> bool { (status & 0xff) == 0x7f } - pub {const} fn WSTOPSIG(status: c_int) -> c_int { + pub const fn WSTOPSIG(status: c_int) -> c_int { // (status >> 8) & 0xff WEXITSTATUS(status) } - pub {const} fn WIFSIGNALED(status: c_int) -> bool { + pub const fn WIFSIGNALED(status: c_int) -> bool { ((status & 0x7f) > 0) && ((status & 0x7f) < 0x7f) } - pub {const} fn WTERMSIG(status: c_int) -> c_int { + pub const fn WTERMSIG(status: c_int) -> c_int { status & 0x7f } - pub {const} fn WIFEXITED(status: c_int) -> bool { + pub const fn WIFEXITED(status: c_int) -> bool { (status & 0xff) == 0 } - pub {const} fn WEXITSTATUS(status: c_int) -> c_int { + pub const fn WEXITSTATUS(status: c_int) -> c_int { (status >> 8) & 0xff } // RTEMS doesn't have native WIFCONTINUED. - pub {const} fn WIFCONTINUED(_status: c_int) -> bool { + pub const fn WIFCONTINUED(_status: c_int) -> bool { true } // RTEMS doesn't have native WCOREDUMP. - pub {const} fn WCOREDUMP(_status: c_int) -> bool { + pub const fn WCOREDUMP(_status: c_int) -> bool { false } } diff --git a/src/unix/nto/mod.rs b/src/unix/nto/mod.rs index 7baf673394b34..2dd3375c3a86d 100644 --- a/src/unix/nto/mod.rs +++ b/src/unix/nto/mod.rs @@ -2608,11 +2608,11 @@ pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { }; const_fn! { - {const} fn _CMSG_ALIGN(len: usize) -> usize { + const fn _CMSG_ALIGN(len: usize) -> usize { len + size_of::() - 1 & !(size_of::() - 1) } - {const} fn _ALIGN(p: usize, b: usize) -> usize { + const fn _ALIGN(p: usize, b: usize) -> usize { (p + b - 1) & !(b - 1) } } @@ -2640,11 +2640,11 @@ f! { (cmsg as *mut c_uchar).offset(_CMSG_ALIGN(size_of::()) as isize) } - pub {const} fn CMSG_LEN(length: c_uint) -> c_uint { + pub const fn CMSG_LEN(length: c_uint) -> c_uint { _CMSG_ALIGN(size_of::()) as c_uint + length } - pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint { + pub const fn CMSG_SPACE(length: c_uint) -> c_uint { (_CMSG_ALIGN(size_of::()) + _CMSG_ALIGN(length as usize)) as c_uint } @@ -2706,51 +2706,51 @@ f! { } safe_f! { - pub {const} fn WIFSTOPPED(status: c_int) -> bool { + pub const fn WIFSTOPPED(status: c_int) -> bool { (status & 0xff) == 0x7f } - pub {const} fn WSTOPSIG(status: c_int) -> c_int { + pub const fn WSTOPSIG(status: c_int) -> c_int { (status >> 8) & 0xff } - pub {const} fn WIFCONTINUED(status: c_int) -> bool { + pub const fn WIFCONTINUED(status: c_int) -> bool { status == 0xffff } - pub {const} fn WIFSIGNALED(status: c_int) -> bool { + pub const fn WIFSIGNALED(status: c_int) -> bool { ((status & 0x7f) + 1) as i8 >= 2 } - pub {const} fn WTERMSIG(status: c_int) -> c_int { + pub const fn WTERMSIG(status: c_int) -> c_int { status & 0x7f } - pub {const} fn WIFEXITED(status: c_int) -> bool { + pub const fn WIFEXITED(status: c_int) -> bool { (status & 0x7f) == 0 } - pub {const} fn WEXITSTATUS(status: c_int) -> c_int { + pub const fn WEXITSTATUS(status: c_int) -> c_int { (status >> 8) & 0xff } - pub {const} fn WCOREDUMP(status: c_int) -> bool { + pub const fn WCOREDUMP(status: c_int) -> bool { (status & 0x80) != 0 } - pub {const} fn IPTOS_ECN(x: u8) -> u8 { + pub const fn IPTOS_ECN(x: u8) -> u8 { x & crate::IPTOS_ECN_MASK } - pub {const} fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { + pub const fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { ((major << 10) | (minor)) as crate::dev_t } - pub {const} fn major(dev: crate::dev_t) -> c_uint { + pub const fn major(dev: crate::dev_t) -> c_uint { ((dev as c_uint) >> 10) & 0x3f } - pub {const} fn minor(dev: crate::dev_t) -> c_uint { + pub const fn minor(dev: crate::dev_t) -> c_uint { (dev as c_uint) & 0x3ff } } diff --git a/src/unix/redox/mod.rs b/src/unix/redox/mod.rs index d9ecf1a45a18f..4a8b2ae3c435d 100644 --- a/src/unix/redox/mod.rs +++ b/src/unix/redox/mod.rs @@ -1094,13 +1094,13 @@ pub const PRIO_USER: c_int = 2; f! { //sys/socket.h - pub {const} fn CMSG_ALIGN(len: size_t) -> size_t { + pub const fn CMSG_ALIGN(len: size_t) -> size_t { (len + size_of::() - 1) & !(size_of::() - 1) } - pub {const} fn CMSG_LEN(length: c_uint) -> c_uint { + pub const fn CMSG_LEN(length: c_uint) -> c_uint { (CMSG_ALIGN(size_of::()) + length as usize) as c_uint } - pub {const} fn CMSG_SPACE(len: c_uint) -> c_uint { + pub const fn CMSG_SPACE(len: c_uint) -> c_uint { (CMSG_ALIGN(len as size_t) + CMSG_ALIGN(size_of::())) as c_uint } @@ -1133,35 +1133,35 @@ f! { } safe_f! { - pub {const} fn WIFSTOPPED(status: c_int) -> bool { + pub const fn WIFSTOPPED(status: c_int) -> bool { (status & 0xff) == 0x7f } - pub {const} fn WSTOPSIG(status: c_int) -> c_int { + pub const fn WSTOPSIG(status: c_int) -> c_int { (status >> 8) & 0xff } - pub {const} fn WIFCONTINUED(status: c_int) -> bool { + pub const fn WIFCONTINUED(status: c_int) -> bool { status == 0xffff } - pub {const} fn WIFSIGNALED(status: c_int) -> bool { + pub const fn WIFSIGNALED(status: c_int) -> bool { ((status & 0x7f) + 1) as i8 >= 2 } - pub {const} fn WTERMSIG(status: c_int) -> c_int { + pub const fn WTERMSIG(status: c_int) -> c_int { status & 0x7f } - pub {const} fn WIFEXITED(status: c_int) -> bool { + pub const fn WIFEXITED(status: c_int) -> bool { (status & 0x7f) == 0 } - pub {const} fn WEXITSTATUS(status: c_int) -> c_int { + pub const fn WEXITSTATUS(status: c_int) -> c_int { (status >> 8) & 0xff } - pub {const} fn WCOREDUMP(status: c_int) -> bool { + pub const fn WCOREDUMP(status: c_int) -> bool { (status & 0x80) != 0 } } diff --git a/src/unix/solarish/mod.rs b/src/unix/solarish/mod.rs index a6219a64437f2..2ebedcbf4653e 100644 --- a/src/unix/solarish/mod.rs +++ b/src/unix/solarish/mod.rs @@ -2391,11 +2391,11 @@ const NEWDEV: c_int = 1; pub const SFV_FD_SELF: c_int = -2; const_fn! { - {const} fn _CMSG_HDR_ALIGN(p: usize) -> usize { + const fn _CMSG_HDR_ALIGN(p: usize) -> usize { (p + _CMSG_HDR_ALIGNMENT - 1) & !(_CMSG_HDR_ALIGNMENT - 1) } - {const} fn _CMSG_DATA_ALIGN(p: usize) -> usize { + const fn _CMSG_DATA_ALIGN(p: usize) -> usize { (p + _CMSG_DATA_ALIGNMENT - 1) & !(_CMSG_DATA_ALIGNMENT - 1) } } @@ -2405,7 +2405,7 @@ f! { _CMSG_DATA_ALIGN(cmsg.offset(1) as usize) as *mut c_uchar } - pub {const} fn CMSG_LEN(length: c_uint) -> c_uint { + pub const fn CMSG_LEN(length: c_uint) -> c_uint { _CMSG_DATA_ALIGN(size_of::()) as c_uint + length } @@ -2431,7 +2431,7 @@ f! { } } - pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint { + pub const fn CMSG_SPACE(length: c_uint) -> c_uint { _CMSG_HDR_ALIGN(size_of::() as usize + length as usize) as c_uint } @@ -2471,39 +2471,39 @@ safe_f! { unsafe { crate::sysconf(_SC_SIGRT_MIN) as c_int } } - pub {const} fn WIFEXITED(status: c_int) -> bool { + pub const fn WIFEXITED(status: c_int) -> bool { (status & 0xFF) == 0 } - pub {const} fn WEXITSTATUS(status: c_int) -> c_int { + pub const fn WEXITSTATUS(status: c_int) -> c_int { (status >> 8) & 0xFF } - pub {const} fn WTERMSIG(status: c_int) -> c_int { + pub const fn WTERMSIG(status: c_int) -> c_int { status & 0x7F } - pub {const} fn WIFCONTINUED(status: c_int) -> bool { + pub const fn WIFCONTINUED(status: c_int) -> bool { (status & 0xffff) == 0xffff } - pub {const} fn WSTOPSIG(status: c_int) -> c_int { + pub const fn WSTOPSIG(status: c_int) -> c_int { (status & 0xff00) >> 8 } - pub {const} fn WIFSIGNALED(status: c_int) -> bool { + pub const fn WIFSIGNALED(status: c_int) -> bool { ((status & 0xff) > 0) && (status & 0xff00 == 0) } - pub {const} fn WIFSTOPPED(status: c_int) -> bool { + pub const fn WIFSTOPPED(status: c_int) -> bool { ((status & 0xff) == 0x7f) && ((status & 0xff00) != 0) } - pub {const} fn WCOREDUMP(status: c_int) -> bool { + pub const fn WCOREDUMP(status: c_int) -> bool { (status & 0x80) != 0 } - pub {const} fn MR_GET_TYPE(flags: c_uint) -> c_uint { + pub const fn MR_GET_TYPE(flags: c_uint) -> c_uint { flags & 0x0000ffff } } diff --git a/src/vxworks/mod.rs b/src/vxworks/mod.rs index 657f85851c8f1..809640d112221 100644 --- a/src/vxworks/mod.rs +++ b/src/vxworks/mod.rs @@ -1072,7 +1072,7 @@ impl Clone for fpos_t { } f! { - pub {const} fn CMSG_ALIGN(len: usize) -> usize { + pub const fn CMSG_ALIGN(len: usize) -> usize { len + size_of::() - 1 & !(size_of::() - 1) } @@ -1100,11 +1100,11 @@ f! { (cmsg as *mut c_uchar).offset(CMSG_ALIGN(size_of::()) as isize) } - pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint { + pub const fn CMSG_SPACE(length: c_uint) -> c_uint { (CMSG_ALIGN(length as usize) + CMSG_ALIGN(size_of::())) as c_uint } - pub {const} fn CMSG_LEN(length: c_uint) -> c_uint { + pub const fn CMSG_LEN(length: c_uint) -> c_uint { CMSG_ALIGN(size_of::()) as c_uint + length } } @@ -1937,22 +1937,22 @@ extern "C" { // wait.h macros safe_f! { - pub {const} fn WIFEXITED(status: c_int) -> bool { + pub const fn WIFEXITED(status: c_int) -> bool { (status & 0xFF00) == 0 } - pub {const} fn WIFSIGNALED(status: c_int) -> bool { + pub const fn WIFSIGNALED(status: c_int) -> bool { (status & 0xFF00) != 0 } - pub {const} fn WIFSTOPPED(status: c_int) -> bool { + pub const fn WIFSTOPPED(status: c_int) -> bool { (status & 0xFF0000) != 0 } - pub {const} fn WEXITSTATUS(status: c_int) -> c_int { + pub const fn WEXITSTATUS(status: c_int) -> c_int { status & 0xFF } - pub {const} fn WTERMSIG(status: c_int) -> c_int { + pub const fn WTERMSIG(status: c_int) -> c_int { (status >> 8) & 0xFF } - pub {const} fn WSTOPSIG(status: c_int) -> c_int { + pub const fn WSTOPSIG(status: c_int) -> c_int { (status >> 16) & 0xFF } } From 7ad2ab9e64d4e5a6f27da7236b3301ff8c60cfdd Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 23 Sep 2025 01:30:01 -0500 Subject: [PATCH 11/12] cleanup: Remove the `const_fn!` macro Now that is okay for functions to be always `const`, this macro doesn't add anything other than the `#[inline]` attribute, which isn't useful for private functions anyway. Thus, remove the macro and leave its contents wherever it is used. (backport ) (cherry picked from commit dcde5cd6b952cccc104308efd169d6bb229453cd) --- src/macros.rs | 14 -------------- src/unix/bsd/freebsdlike/dragonfly/mod.rs | 6 ++---- src/unix/bsd/freebsdlike/freebsd/mod.rs | 6 ++---- src/unix/bsd/netbsdlike/netbsd/mod.rs | 6 ++---- src/unix/bsd/netbsdlike/openbsd/mod.rs | 6 ++---- src/unix/cygwin/mod.rs | 6 ++---- src/unix/haiku/mod.rs | 6 ++---- src/unix/hurd/mod.rs | 6 ++---- src/unix/linux_like/mod.rs | 6 ++---- src/unix/nto/mod.rs | 12 +++++------- src/unix/solarish/mod.rs | 12 +++++------- 11 files changed, 26 insertions(+), 60 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 1ffa71e02df37..6906da6bd70da 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -330,20 +330,6 @@ macro_rules! safe_f { )+}; } -/// Define a nonpublic function. -macro_rules! const_fn { - ($( - $(#[$attr:meta])* - const fn $i:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty - $body:block - )*) => ($( - #[inline] - $(#[$attr])* - const fn $i($($arg: $argty),*) -> $ret - $body - )*) -} - macro_rules! __item { ($i:item) => { $i diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs index 930c7089131f1..dbf18ebb64dc6 100644 --- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs @@ -1419,10 +1419,8 @@ pub const RTAX_MPLS2: c_int = 9; pub const RTAX_MPLS3: c_int = 10; pub const RTAX_MAX: c_int = 11; -const_fn! { - const fn _CMSG_ALIGN(n: usize) -> usize { - (n + (size_of::() - 1)) & !(size_of::() - 1) - } +const fn _CMSG_ALIGN(n: usize) -> usize { + (n + (size_of::() - 1)) & !(size_of::() - 1) } f! { diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index 0987617a0f3fc..a5166d4e15c75 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -4749,10 +4749,8 @@ pub const fn MAP_ALIGNED(a: c_int) -> c_int { a << 24 } -const_fn! { - const fn _ALIGN(p: usize) -> usize { - (p + _ALIGNBYTES) & !_ALIGNBYTES - } +const fn _ALIGN(p: usize) -> usize { + (p + _ALIGNBYTES) & !_ALIGNBYTES } f! { diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index bf241a981b8e4..fba5391e14c44 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -2301,10 +2301,8 @@ pub const TFD_NONBLOCK: i32 = crate::O_NONBLOCK; pub const TFD_TIMER_ABSTIME: i32 = crate::O_WRONLY; pub const TFD_TIMER_CANCEL_ON_SET: i32 = crate::O_RDWR; -const_fn! { - const fn _ALIGN(p: usize) -> usize { - (p + _ALIGNBYTES) & !_ALIGNBYTES - } +const fn _ALIGN(p: usize) -> usize { + (p + _ALIGNBYTES) & !_ALIGNBYTES } f! { diff --git a/src/unix/bsd/netbsdlike/openbsd/mod.rs b/src/unix/bsd/netbsdlike/openbsd/mod.rs index 5a5307c499166..d2937bc16911b 100644 --- a/src/unix/bsd/netbsdlike/openbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/openbsd/mod.rs @@ -1868,10 +1868,8 @@ pub const RTAX_STATIC: c_int = 13; pub const RTAX_SEARCH: c_int = 14; pub const RTAX_MAX: c_int = 15; -const_fn! { - const fn _ALIGN(p: usize) -> usize { - (p + _ALIGNBYTES) & !_ALIGNBYTES - } +const fn _ALIGN(p: usize) -> usize { + (p + _ALIGNBYTES) & !_ALIGNBYTES } f! { diff --git a/src/unix/cygwin/mod.rs b/src/unix/cygwin/mod.rs index 6d94a00ddb25a..12e30f3f9016c 100644 --- a/src/unix/cygwin/mod.rs +++ b/src/unix/cygwin/mod.rs @@ -1928,10 +1928,8 @@ safe_f! { } } -const_fn! { - const fn CMSG_ALIGN(len: usize) -> usize { - len + size_of::() - 1 & !(size_of::() - 1) - } +const fn CMSG_ALIGN(len: usize) -> usize { + len + size_of::() - 1 & !(size_of::() - 1) } extern "C" { diff --git a/src/unix/haiku/mod.rs b/src/unix/haiku/mod.rs index e1b31b32338f7..964598e97ca35 100644 --- a/src/unix/haiku/mod.rs +++ b/src/unix/haiku/mod.rs @@ -1514,10 +1514,8 @@ pub const POSIX_SPAWN_SETSIGDEF: c_int = 0x10; pub const POSIX_SPAWN_SETSIGMASK: c_int = 0x20; pub const POSIX_SPAWN_SETSID: c_int = 0x40; -const_fn! { - const fn CMSG_ALIGN(len: usize) -> usize { - len + size_of::() - 1 & !(size_of::() - 1) - } +const fn CMSG_ALIGN(len: usize) -> usize { + len + size_of::() - 1 & !(size_of::() - 1) } f! { diff --git a/src/unix/hurd/mod.rs b/src/unix/hurd/mod.rs index 5d63937a97fc7..24e9fe56f392d 100644 --- a/src/unix/hurd/mod.rs +++ b/src/unix/hurd/mod.rs @@ -3414,10 +3414,8 @@ pub const PTHREAD_STACK_MIN: size_t = 0; // Non-public helper constants const _UTSNAME_LENGTH: usize = 1024; -const_fn! { - const fn CMSG_ALIGN(len: usize) -> usize { - (len + size_of::() - 1) & !(size_of::() - 1) - } +const fn CMSG_ALIGN(len: usize) -> usize { + (len + size_of::() - 1) & !(size_of::() - 1) } // functions diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs index 2f7661d25105d..fd3fa996caad4 100644 --- a/src/unix/linux_like/mod.rs +++ b/src/unix/linux_like/mod.rs @@ -1784,10 +1784,8 @@ cfg_if! { } } -const_fn! { - const fn CMSG_ALIGN(len: usize) -> usize { - (len + size_of::() - 1) & !(size_of::() - 1) - } +const fn CMSG_ALIGN(len: usize) -> usize { + (len + size_of::() - 1) & !(size_of::() - 1) } f! { diff --git a/src/unix/nto/mod.rs b/src/unix/nto/mod.rs index 2dd3375c3a86d..75f5b56902f7f 100644 --- a/src/unix/nto/mod.rs +++ b/src/unix/nto/mod.rs @@ -2607,14 +2607,12 @@ pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { __spare: 0, }; -const_fn! { - const fn _CMSG_ALIGN(len: usize) -> usize { - len + size_of::() - 1 & !(size_of::() - 1) - } +const fn _CMSG_ALIGN(len: usize) -> usize { + len + size_of::() - 1 & !(size_of::() - 1) +} - const fn _ALIGN(p: usize, b: usize) -> usize { - (p + b - 1) & !(b - 1) - } +const fn _ALIGN(p: usize, b: usize) -> usize { + (p + b - 1) & !(b - 1) } f! { diff --git a/src/unix/solarish/mod.rs b/src/unix/solarish/mod.rs index 2ebedcbf4653e..d8b32dfc0aae9 100644 --- a/src/unix/solarish/mod.rs +++ b/src/unix/solarish/mod.rs @@ -2390,14 +2390,12 @@ const NEWDEV: c_int = 1; // sys/sendfile.h pub const SFV_FD_SELF: c_int = -2; -const_fn! { - const fn _CMSG_HDR_ALIGN(p: usize) -> usize { - (p + _CMSG_HDR_ALIGNMENT - 1) & !(_CMSG_HDR_ALIGNMENT - 1) - } +const fn _CMSG_HDR_ALIGN(p: usize) -> usize { + (p + _CMSG_HDR_ALIGNMENT - 1) & !(_CMSG_HDR_ALIGNMENT - 1) +} - const fn _CMSG_DATA_ALIGN(p: usize) -> usize { - (p + _CMSG_DATA_ALIGNMENT - 1) & !(_CMSG_DATA_ALIGNMENT - 1) - } +const fn _CMSG_DATA_ALIGN(p: usize) -> usize { + (p + _CMSG_DATA_ALIGNMENT - 1) & !(_CMSG_DATA_ALIGNMENT - 1) } f! { From d5584cdae632b41b95c1d5eb132d3dab0c11df06 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 23 Sep 2025 03:33:43 -0500 Subject: [PATCH 12/12] Warn on missing debug implementations This was removed by accident; only the `feature = "rustc-dep-of-std"` gate should have been removed. Fixes: a6e75638ce4e ("Always implement `Debug`") (backport ) (cherry picked from commit 833eb194331a3a0bfb9a720b47606c0ebc145a64) --- src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 39cbbf809f0ce..aa919b5ca038e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,11 @@ unused_macros, unused_macro_rules, )] +#![warn( + missing_copy_implementations, + missing_debug_implementations, + safe_packed_borrows +)] // Prepare for a future upgrade #![warn(rust_2024_compatibility)] // Things missing for 2024 that are blocked on MSRV or breakage @@ -25,7 +30,6 @@ #![cfg_attr(feature = "rustc-dep-of-std", allow(internal_features))] // DIFF(1.0): The thread local references that raise this lint were removed in 1.0 #![cfg_attr(feature = "rustc-dep-of-std", allow(static_mut_refs))] -#![warn(missing_copy_implementations, safe_packed_borrows)] #![cfg_attr(not(feature = "rustc-dep-of-std"), no_std)] #![cfg_attr(feature = "rustc-dep-of-std", no_core)]