diff --git a/Cargo.toml b/Cargo.toml index 0df83978a..a90bf738c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -259,6 +259,7 @@ check-cfg = [ 'cfg(linux_kernel)', 'cfg(linux_like)', 'cfg(linux_raw)', + 'cfg(lower_upper_exp_for_non_zero)', 'cfg(netbsdlike)', 'cfg(rustc_attrs)', 'cfg(solarish)', diff --git a/build.rs b/build.rs index d2d6541f4..981e82612 100644 --- a/build.rs +++ b/build.rs @@ -79,6 +79,11 @@ fn main() { use_feature("static_assertions"); } + // `LowerExp`/`UpperExp` for `NonZeroI32` etc. + if has_lower_upper_exp_for_non_zero() { + use_feature("lower_upper_exp_for_non_zero"); + } + // WASI support can utilize wasi_ext if present. if os == "wasi" { use_feature_or_nothing("wasi_ext"); @@ -188,6 +193,12 @@ fn use_thumb_mode() -> bool { !can_compile("pub unsafe fn f() { core::arch::asm!(\"udf #16\", in(\"r7\") 0); }") } +fn has_lower_upper_exp_for_non_zero() -> bool { + // LowerExp/UpperExp for NonZero* were added in Rust 1.84. + // + can_compile("fn a(x: &core::num::NonZeroI32, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { core::fmt::LowerExp::fmt(x, f) }") +} + fn use_feature_or_nothing(feature: &str) { if has_feature(feature) { use_feature(feature); diff --git a/src/pid.rs b/src/pid.rs index 0c23927fb..fc0dc9e68 100644 --- a/src/pid.rs +++ b/src/pid.rs @@ -127,11 +127,13 @@ impl fmt::UpperHex for Pid { self.0.fmt(f) } } +#[cfg(lower_upper_exp_for_non_zero)] impl fmt::LowerExp for Pid { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } +#[cfg(lower_upper_exp_for_non_zero)] impl fmt::UpperExp for Pid { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f)