Skip to content

Commit 18874fc

Browse files
committed
Update SAFETY documentation
1 parent 82124c6 commit 18874fc

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/distr/integer.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl Distribution<__m128i> for StandardUniform {
119119
rng.fill_bytes(&mut buf);
120120
// x86 is little endian so no need for conversion
121121

122-
// SAFETY: All representations of the source are also representations of the target.
122+
// SAFETY: All byte sequences of `buf` represent values of the output type.
123123
unsafe { core::mem::transmute(buf) }
124124
}
125125
}
@@ -132,7 +132,7 @@ impl Distribution<__m256i> for StandardUniform {
132132
rng.fill_bytes(&mut buf);
133133
// x86 is little endian so no need for conversion
134134

135-
// SAFETY: All representations of the source are also representations of the target.
135+
// SAFETY: All byte sequences of `buf` represent values of the output type.
136136
unsafe { core::mem::transmute(buf) }
137137
}
138138
}
@@ -148,7 +148,7 @@ impl Distribution<__m512i> for StandardUniform {
148148
rng.fill_bytes(&mut buf);
149149
// x86 is little endian so no need for conversion
150150

151-
// SAFETY: All representations of the source are also representations of the target.
151+
// SAFETY: All byte sequences of `buf` represent values of the output type.
152152
unsafe { core::mem::transmute(buf) }
153153
}
154154
}

src/distr/other.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl Distribution<char> for StandardUniform {
118118
if n <= 0xDFFF {
119119
n -= GAP_SIZE;
120120
}
121-
// SAFETY: The representation of `n` is a valid representation of `u32`.
121+
// SAFETY: We ensure above that `n` represents a `char`.
122122
unsafe { char::from_u32_unchecked(n) }
123123
}
124124
}

src/rng.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ impl Fill for [u8] {
396396
/// Implement `Fill` for given type `T`.
397397
///
398398
/// # Safety
399-
/// All representations of `[u8; size_of::<T>()]` are also representations of `T`.
399+
/// All bit patterns of `[u8; size_of::<T>()]` represent values of `T`.
400400
macro_rules! unsafe_impl_fill {
401401
() => {};
402402
($t:ty) => {
@@ -405,7 +405,7 @@ macro_rules! unsafe_impl_fill {
405405
if self.len() > 0 {
406406
let size = mem::size_of_val(self);
407407
rng.fill_bytes(
408-
// SAFETY: `self` is not borrowed and all byte sequences are representations of `T`.
408+
// SAFETY: `self` is not borrowed and all byte sequences represent values of `T`.
409409
unsafe {
410410
slice::from_raw_parts_mut(self.as_mut_ptr()
411411
as *mut u8,
@@ -425,7 +425,7 @@ macro_rules! unsafe_impl_fill {
425425
if self.len() > 0 {
426426
let size = self.len() * mem::size_of::<$t>();
427427
rng.fill_bytes(
428-
// SAFETY: `self` is not borrowed and all byte sequences are representations of `T`.
428+
// SAFETY: `self` is not borrowed and all byte sequences represent values of `T`.
429429
unsafe {
430430
slice::from_raw_parts_mut(self.as_mut_ptr()
431431
as *mut u8,
@@ -448,9 +448,9 @@ macro_rules! unsafe_impl_fill {
448448
}
449449
}
450450

451-
// SAFETY: All representations of `[u8; size_of::<u*>()]` are representations of `u*`.
451+
// SAFETY: All bit patterns of `[u8; size_of::<T>()]` represent values of `u*`.
452452
unsafe_impl_fill!(u16, u32, u64, u128,);
453-
// SAFETY: All representations of `[u8; size_of::<i*>()]` are representations of `i*`.
453+
// SAFETY: All bit patterns of `[u8; size_of::<T>()]` represent values of `i*`.
454454
unsafe_impl_fill!(i8, i16, i32, i64, i128,);
455455

456456
impl<T, const N: usize> Fill for [T; N]

0 commit comments

Comments
 (0)