From 71fd0cf1bbce4c7ebdbe516e3a25222627d8e995 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sat, 17 Jan 2026 20:57:19 -0700 Subject: [PATCH] ctutils: remove `target_pointer_width` gating From #1387, via rustc itself: expected values for `target_pointer_width` are: `16`, `32`, and `64` So these impls should actually be ubiquitously available, for now. If we remove the gating in this crate, then all we need to do to handle new pointer widths is ship a fix for `cmov`. --- ctutils/src/traits/ct_lookup.rs | 4 ---- ctutils/src/traits/ct_select.rs | 36 +++------------------------------ 2 files changed, 3 insertions(+), 37 deletions(-) diff --git a/ctutils/src/traits/ct_lookup.rs b/ctutils/src/traits/ct_lookup.rs index 5c3db84b..0bbecca5 100644 --- a/ctutils/src/traits/ct_lookup.rs +++ b/ctutils/src/traits/ct_lookup.rs @@ -99,8 +99,6 @@ mod tests { assert!(EXAMPLE.ct_lookup(4u32).is_none().to_bool()); } - // usize only has a `CtEq` impl on 32-bit and 64-bit targets currently - #[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))] #[test] fn ct_lookup_usize() { assert_eq!(EXAMPLE.ct_lookup(0usize).unwrap(), 1); @@ -125,8 +123,6 @@ mod tests { assert!(EXAMPLE.ct_lookup(4u32).is_none().to_bool()); } - // usize only has a `CtEq` impl on 32-bit and 64-bit targets currently - #[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))] #[test] fn ct_lookup_usize() { assert_eq!(EXAMPLE.ct_lookup(0usize).unwrap(), 1); diff --git a/ctutils/src/traits/ct_select.rs b/ctutils/src/traits/ct_select.rs index e38cdf05..55b2e045 100644 --- a/ctutils/src/traits/ct_select.rs +++ b/ctutils/src/traits/ct_select.rs @@ -101,7 +101,9 @@ macro_rules! impl_ct_select_with_ct_assign { }; } -impl_ct_select_with_ct_assign!(i8, i16, i32, i64, i128, u8, u16, u32, u64, u128); +impl_ct_select_with_ct_assign!( + i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize +); /// Impl `CtSelect` for `NonZero` by calling the `CtSelect` impl for `T`. macro_rules! impl_ct_select_for_nonzero_integer { @@ -135,38 +137,6 @@ impl_ct_select_for_nonzero_integer!( NonZeroU128 ); -#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))] -impl CtSelect for isize { - #[cfg(target_pointer_width = "32")] - #[inline] - fn ct_select(&self, other: &Self, choice: Choice) -> Self { - (*self as i32).ct_select(&(*other as i32), choice) as isize - } - - #[cfg(target_pointer_width = "64")] - #[allow(clippy::cast_possible_truncation)] - #[inline] - fn ct_select(&self, other: &Self, choice: Choice) -> Self { - (*self as i64).ct_select(&(*other as i64), choice) as isize - } -} - -#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))] -impl CtSelect for usize { - #[cfg(target_pointer_width = "32")] - #[inline] - fn ct_select(&self, other: &Self, choice: Choice) -> Self { - (*self as u32).ct_select(&(*other as u32), choice) as usize - } - - #[cfg(target_pointer_width = "64")] - #[allow(clippy::cast_possible_truncation)] - #[inline] - fn ct_select(&self, other: &Self, choice: Choice) -> Self { - (*self as u64).ct_select(&(*other as u64), choice) as usize - } -} - impl CtSelect for cmp::Ordering { fn ct_select(&self, other: &Self, choice: Choice) -> Self { // `Ordering` is `#[repr(i8)]` where: