From 8372b50a6faa2883a6bd15fde121fcb47e6d43e9 Mon Sep 17 00:00:00 2001 From: dybucc <149513579+dybucc@users.noreply.github.com> Date: Thu, 18 Jun 2026 15:53:52 +0200 Subject: [PATCH 1/2] feat: add macro to declare unstable constants This patch adds a new macro that can be used for declaring constants when these are known to possibly change upstream across target OS/ABI versions. --- src/macros.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/macros.rs b/src/macros.rs index 0149b1fd18466..5c5b8c2deac79 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -402,6 +402,21 @@ macro_rules! offset_of { }}; } +/// Defines constants with an accompanying doc comment pointing out their +/// instability, and links to the crate documentation for usage guidelines. +macro_rules! ct { + ($($it:item)+) => { +$( +/// This constant, among others often used in C for the purposes of denoting the +/// latest value or limit in a set of constants, is likely to change upstream. +/// For correct usage, see the [crate-level documentation][docs]. +/// +/// [docs]: index.html#usage-recommendations +$it +)+ + }; +} + #[cfg(test)] mod tests { use core::any::TypeId; From d6d6fcdf33cfa4b64a1cea178227a9be5feba4af Mon Sep 17 00:00:00 2001 From: dybucc <149513579+dybucc@users.noreply.github.com> Date: Thu, 28 May 2026 11:59:50 +0200 Subject: [PATCH 2/2] refactor: annotate *LAST constants as unstable Constants matching the *LAST naming scheme, and whose purpose fits that of a "delimitter" value have been annotated with a documentation comment pointing to updated usage guidelines for the libc crate. --- src/solid/mod.rs | 5 ++++- src/unix/bsd/netbsdlike/openbsd/mod.rs | 5 ++++- src/unix/linux_like/android/mod.rs | 15 ++++++++++++--- src/unix/linux_like/linux/mod.rs | 22 +++++++++++++++++----- src/unix/solarish/illumos.rs | 4 +++- src/unix/solarish/solaris.rs | 4 +++- 6 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/solid/mod.rs b/src/solid/mod.rs index 0182f8150df67..a4d653bca70d1 100644 --- a/src/solid/mod.rs +++ b/src/solid/mod.rs @@ -219,7 +219,10 @@ pub const LC_MONETARY: c_int = 3; pub const LC_NUMERIC: c_int = 4; pub const LC_TIME: c_int = 5; pub const LC_MESSAGES: c_int = 6; -pub const _LC_LAST: c_int = 7; + +ct! { + pub const _LC_LAST: c_int = 7; +} pub const EPERM: c_int = 1; pub const ENOENT: c_int = 2; diff --git a/src/unix/bsd/netbsdlike/openbsd/mod.rs b/src/unix/bsd/netbsdlike/openbsd/mod.rs index 6242505420559..96c0aca7204c2 100644 --- a/src/unix/bsd/netbsdlike/openbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/openbsd/mod.rs @@ -1736,7 +1736,10 @@ pub const LC_NUMERIC_MASK: c_int = 1 << crate::LC_NUMERIC; pub const LC_TIME_MASK: c_int = 1 << crate::LC_TIME; pub const LC_MESSAGES_MASK: c_int = 1 << crate::LC_MESSAGES; -const _LC_LAST: c_int = 7; +ct! { + const _LC_LAST: c_int = 7; +} + pub const LC_ALL_MASK: c_int = (1 << _LC_LAST) - 2; pub const LC_GLOBAL_LOCALE: crate::locale_t = -1isize as crate::locale_t; diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index b262ff8a142c7..ee9a80ceb60e4 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -1937,7 +1937,10 @@ pub const NF_BR_PRI_BRNF: c_int = 0; pub const NF_BR_PRI_NAT_DST_OTHER: c_int = 100; pub const NF_BR_PRI_FILTER_OTHER: c_int = 200; pub const NF_BR_PRI_NAT_SRC: c_int = 300; -pub const NF_BR_PRI_LAST: c_int = crate::INT_MAX; + +ct! { + pub const NF_BR_PRI_LAST: c_int = crate::INT_MAX; +} // linux/netfilter_ipv4.h pub const NF_IP_PRE_ROUTING: c_int = 0; @@ -1961,7 +1964,10 @@ pub const NF_IP_PRI_NAT_SRC: c_int = 100; pub const NF_IP_PRI_SELINUX_LAST: c_int = 225; pub const NF_IP_PRI_CONNTRACK_HELPER: c_int = 300; pub const NF_IP_PRI_CONNTRACK_CONFIRM: c_int = crate::INT_MAX; -pub const NF_IP_PRI_LAST: c_int = crate::INT_MAX; + +ct! { + pub const NF_IP_PRI_LAST: c_int = crate::INT_MAX; +} // linux/netfilter_ipv6.h pub const NF_IP6_PRE_ROUTING: c_int = 0; @@ -1984,7 +1990,10 @@ pub const NF_IP6_PRI_SECURITY: c_int = 50; pub const NF_IP6_PRI_NAT_SRC: c_int = 100; pub const NF_IP6_PRI_SELINUX_LAST: c_int = 225; pub const NF_IP6_PRI_CONNTRACK_HELPER: c_int = 300; -pub const NF_IP6_PRI_LAST: c_int = crate::INT_MAX; + +ct! { + pub const NF_IP6_PRI_LAST: c_int = crate::INT_MAX; +} // linux/netfilter_ipv6/ip6_tables.h pub const IP6T_SO_ORIGINAL_DST: c_int = 80; diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 081b16d78ce39..b50b9e174b852 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -2180,7 +2180,10 @@ pub const NF_BR_PRI_BRNF: c_int = 0; pub const NF_BR_PRI_NAT_DST_OTHER: c_int = 100; pub const NF_BR_PRI_FILTER_OTHER: c_int = 200; pub const NF_BR_PRI_NAT_SRC: c_int = 300; -pub const NF_BR_PRI_LAST: c_int = crate::INT_MAX; + +ct! { + pub const NF_BR_PRI_LAST: c_int = crate::INT_MAX; +} // linux/netfilter_ipv4.h pub const NF_IP_PRE_ROUTING: c_int = 0; @@ -2204,7 +2207,10 @@ pub const NF_IP_PRI_NAT_SRC: c_int = 100; pub const NF_IP_PRI_SELINUX_LAST: c_int = 225; pub const NF_IP_PRI_CONNTRACK_HELPER: c_int = 300; pub const NF_IP_PRI_CONNTRACK_CONFIRM: c_int = crate::INT_MAX; -pub const NF_IP_PRI_LAST: c_int = crate::INT_MAX; + +ct! { + pub const NF_IP_PRI_LAST: c_int = crate::INT_MAX; +} // linux/netfilter_ipv6.h pub const NF_IP6_PRE_ROUTING: c_int = 0; @@ -2227,7 +2233,10 @@ pub const NF_IP6_PRI_SECURITY: c_int = 50; pub const NF_IP6_PRI_NAT_SRC: c_int = 100; pub const NF_IP6_PRI_SELINUX_LAST: c_int = 225; pub const NF_IP6_PRI_CONNTRACK_HELPER: c_int = 300; -pub const NF_IP6_PRI_LAST: c_int = crate::INT_MAX; + +ct! { + pub const NF_IP6_PRI_LAST: c_int = crate::INT_MAX; +} // linux/netfilter_ipv6/ip6_tables.h pub const IP6T_SO_ORIGINAL_DST: c_int = 80; @@ -2304,10 +2313,13 @@ pub const SIOCGIWENCODEEXT: c_ulong = 0x8B35; pub const SIOCSIWPMKSA: c_ulong = 0x8B36; pub const SIOCIWFIRSTPRIV: c_ulong = 0x8BE0; -pub const SIOCIWLASTPRIV: c_ulong = 0x8BFF; + +ct! { + pub const SIOCIWLASTPRIV: c_ulong = 0x8BFF; + pub const SIOCIWLAST: c_ulong = SIOCIWLASTPRIV; +} pub const SIOCIWFIRST: c_ulong = 0x8B00; -pub const SIOCIWLAST: c_ulong = SIOCIWLASTPRIV; pub const IWEVTXDROP: c_ulong = 0x8C00; pub const IWEVQUAL: c_ulong = 0x8C01; diff --git a/src/unix/solarish/illumos.rs b/src/unix/solarish/illumos.rs index b31c31bd1f6c8..8112f05aab0be 100644 --- a/src/unix/solarish/illumos.rs +++ b/src/unix/solarish/illumos.rs @@ -152,7 +152,9 @@ pub const LOCK_EX: c_int = 2; pub const LOCK_NB: c_int = 4; pub const LOCK_UN: c_int = 8; -pub const _PC_LAST: c_int = 101; +ct! { + pub const _PC_LAST: c_int = 101; +} pub const _CS_PATH: c_int = 65; diff --git a/src/unix/solarish/solaris.rs b/src/unix/solarish/solaris.rs index 992df9ddc0ad9..bf331b28456a9 100644 --- a/src/unix/solarish/solaris.rs +++ b/src/unix/solarish/solaris.rs @@ -132,7 +132,9 @@ pub const F_DUPFD_CLOFORK: c_int = 49; pub const F_DUP2FD_CLOEXEC: c_int = 48; pub const F_DUP2FD_CLOFORK: c_int = 50; -pub const _PC_LAST: c_int = 102; +ct! { + pub const _PC_LAST: c_int = 102; +} pub const PRIV_PROC_SENSITIVE: c_uint = 0x0008; pub const PRIV_PFEXEC_AUTH: c_uint = 0x0200;