Skip to content

Commit b304122

Browse files
committed
Remove all support for directly generating usize, isize values
1 parent 2afb75b commit b304122

File tree

6 files changed

+9
-61
lines changed

6 files changed

+9
-61
lines changed

src/distr/integer.rs

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use core::arch::x86_64::__m512i;
1919
#[cfg(target_arch = "x86_64")]
2020
use core::arch::x86_64::{__m128i, __m256i};
2121
use core::num::{
22-
NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128,
23-
NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize,
22+
NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroU128, NonZeroU16,
23+
NonZeroU32, NonZeroU64, NonZeroU8,
2424
};
2525
#[cfg(feature = "simd_support")]
2626
use core::simd::*;
@@ -63,20 +63,6 @@ impl Distribution<u128> for Standard {
6363
}
6464
}
6565

66-
impl Distribution<usize> for Standard {
67-
#[inline]
68-
#[cfg(any(target_pointer_width = "32", target_pointer_width = "16"))]
69-
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> usize {
70-
rng.next_u32() as usize
71-
}
72-
73-
#[inline]
74-
#[cfg(target_pointer_width = "64")]
75-
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> usize {
76-
rng.next_u64() as usize
77-
}
78-
}
79-
8066
macro_rules! impl_int_from_uint {
8167
($ty:ty, $uty:ty) => {
8268
impl Distribution<$ty> for Standard {
@@ -93,7 +79,6 @@ impl_int_from_uint! { i16, u16 }
9379
impl_int_from_uint! { i32, u32 }
9480
impl_int_from_uint! { i64, u64 }
9581
impl_int_from_uint! { i128, u128 }
96-
impl_int_from_uint! { isize, usize }
9782

9883
macro_rules! impl_nzint {
9984
($ty:ty, $new:path) => {
@@ -114,14 +99,12 @@ impl_nzint!(NonZeroU16, NonZeroU16::new);
11499
impl_nzint!(NonZeroU32, NonZeroU32::new);
115100
impl_nzint!(NonZeroU64, NonZeroU64::new);
116101
impl_nzint!(NonZeroU128, NonZeroU128::new);
117-
impl_nzint!(NonZeroUsize, NonZeroUsize::new);
118102

119103
impl_nzint!(NonZeroI8, NonZeroI8::new);
120104
impl_nzint!(NonZeroI16, NonZeroI16::new);
121105
impl_nzint!(NonZeroI32, NonZeroI32::new);
122106
impl_nzint!(NonZeroI64, NonZeroI64::new);
123107
impl_nzint!(NonZeroI128, NonZeroI128::new);
124-
impl_nzint!(NonZeroIsize, NonZeroIsize::new);
125108

126109
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
127110
macro_rules! x86_intrinsic_impl {
@@ -163,7 +146,7 @@ macro_rules! simd_impl {
163146
}
164147

165148
#[cfg(feature = "simd_support")]
166-
simd_impl!(u8, i8, u16, i16, u32, i32, u64, i64, usize, isize);
149+
simd_impl!(u8, i8, u16, i16, u32, i32, u64, i64);
167150

168151
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
169152
x86_intrinsic_impl!(
@@ -191,14 +174,12 @@ mod tests {
191174
fn test_integers() {
192175
let mut rng = crate::test::rng(806);
193176

194-
rng.sample::<isize, _>(Standard);
195177
rng.sample::<i8, _>(Standard);
196178
rng.sample::<i16, _>(Standard);
197179
rng.sample::<i32, _>(Standard);
198180
rng.sample::<i64, _>(Standard);
199181
rng.sample::<i128, _>(Standard);
200182

201-
rng.sample::<usize, _>(Standard);
202183
rng.sample::<u8, _>(Standard);
203184
rng.sample::<u16, _>(Standard);
204185
rng.sample::<u32, _>(Standard);
@@ -239,17 +220,6 @@ mod tests {
239220
111087889832015897993126088499035356354,
240221
],
241222
);
242-
#[cfg(any(target_pointer_width = "32", target_pointer_width = "16"))]
243-
test_samples(0usize, &[2220326409, 2575017975, 2018088303]);
244-
#[cfg(target_pointer_width = "64")]
245-
test_samples(
246-
0usize,
247-
&[
248-
11059617991457472009,
249-
16096616328739788143,
250-
1487364411147516184,
251-
],
252-
);
253223

254224
test_samples(0i8, &[9, -9, 111]);
255225
// Skip further i* types: they are simple reinterpretation of u* samples

src/distr/uniform_int.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,10 @@ uniform_int_impl! { i16, u16, u32 }
258258
uniform_int_impl! { i32, u32, u32 }
259259
uniform_int_impl! { i64, u64, u64 }
260260
uniform_int_impl! { i128, u128, u128 }
261-
uniform_int_impl! { isize, usize, usize }
262261
uniform_int_impl! { u8, u8, u32 }
263262
uniform_int_impl! { u16, u16, u32 }
264263
uniform_int_impl! { u32, u32, u32 }
265264
uniform_int_impl! { u64, u64, u64 }
266-
uniform_int_impl! { usize, usize, usize }
267265
uniform_int_impl! { u128, u128, u128 }
268266

269267
#[cfg(feature = "simd_support")]
@@ -476,7 +474,7 @@ mod tests {
476474
);)*
477475
}};
478476
}
479-
t!(i8, i16, i32, i64, isize, u8, u16, u32, u64, usize, i128, u128);
477+
t!(i8, i16, i32, i64, u8, u16, u32, u64, i128, u128);
480478

481479
#[cfg(feature = "simd_support")]
482480
{

src/distr/utils.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -124,26 +124,6 @@ macro_rules! wmul_impl_large {
124124
}
125125
wmul_impl_large! { u128, 64 }
126126

127-
macro_rules! wmul_impl_usize {
128-
($ty:ty) => {
129-
impl WideningMultiply for usize {
130-
type Output = (usize, usize);
131-
132-
#[inline(always)]
133-
fn wmul(self, x: usize) -> Self::Output {
134-
let (high, low) = (self as $ty).wmul(x as $ty);
135-
(high as usize, low as usize)
136-
}
137-
}
138-
};
139-
}
140-
#[cfg(target_pointer_width = "16")]
141-
wmul_impl_usize! { u16 }
142-
#[cfg(target_pointer_width = "32")]
143-
wmul_impl_usize! { u32 }
144-
#[cfg(target_pointer_width = "64")]
145-
wmul_impl_usize! { u64 }
146-
147127
#[cfg(feature = "simd_support")]
148128
mod simd_wmul {
149129
use super::*;

src/distr/weighted_index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ mod test {
696696
#[test]
697697
fn overflow() {
698698
assert_eq!(
699-
WeightedIndex::new([2, usize::MAX]),
699+
WeightedIndex::new([2, u32::MAX]),
700700
Err(WeightError::Overflow)
701701
);
702702
}

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,13 @@ mod test {
179179
#[test]
180180
#[cfg(all(feature = "std", feature = "std_rng", feature = "getrandom"))]
181181
fn test_random() {
182-
let _n: usize = random();
182+
let _n: u64 = random();
183183
let _f: f32 = random();
184184
let _o: Option<Option<i8>> = random();
185185
#[allow(clippy::type_complexity)]
186186
let _many: (
187187
(),
188-
(usize, isize, Option<(u32, (bool,))>),
188+
Option<(u32, (bool,))>,
189189
(u8, i8, u16, i16, u32, i32, u64, i64),
190190
(f32, (f64, (f64,))),
191191
) = random();

src/rng.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,8 @@ macro_rules! impl_fill {
486486
}
487487
}
488488

489-
impl_fill!(u16, u32, u64, usize, u128,);
490-
impl_fill!(i8, i16, i32, i64, isize, i128,);
489+
impl_fill!(u16, u32, u64, u128,);
490+
impl_fill!(i8, i16, i32, i64, i128,);
491491

492492
impl<T, const N: usize> Fill for [T; N]
493493
where

0 commit comments

Comments
 (0)