Skip to content

Commit bdf5ec7

Browse files
committed
Document remaining internal unsafety, and deny undocumented unsafety
1 parent c44a608 commit bdf5ec7

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
lines changed

crates/core_simd/src/elements/float.rs

+5
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,20 @@ macro_rules! impl_trait {
202202
#[inline]
203203
fn to_bits(self) -> Simd<$bits_ty, LANES> {
204204
assert_eq!(core::mem::size_of::<Self>(), core::mem::size_of::<Self::Bits>());
205+
// Safety: transmuting between vector types is safe
205206
unsafe { core::mem::transmute_copy(&self) }
206207
}
207208

208209
#[inline]
209210
fn from_bits(bits: Simd<$bits_ty, LANES>) -> Self {
210211
assert_eq!(core::mem::size_of::<Self>(), core::mem::size_of::<Self::Bits>());
212+
// Safety: transmuting between vector types is safe
211213
unsafe { core::mem::transmute_copy(&bits) }
212214
}
213215

214216
#[inline]
215217
fn abs(self) -> Self {
218+
// Safety: `self` is a float vector
216219
unsafe { intrinsics::simd_fabs(self) }
217220
}
218221

@@ -283,11 +286,13 @@ macro_rules! impl_trait {
283286

284287
#[inline]
285288
fn simd_min(self, other: Self) -> Self {
289+
// Safety: `self` and `other` are float vectors
286290
unsafe { intrinsics::simd_fmin(self, other) }
287291
}
288292

289293
#[inline]
290294
fn simd_max(self, other: Self) -> Self {
295+
// Safety: `self` and `other` are floating point vectors
291296
unsafe { intrinsics::simd_fmax(self, other) }
292297
}
293298

crates/core_simd/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#![cfg_attr(feature = "generic_const_exprs", feature(generic_const_exprs))]
1313
#![cfg_attr(feature = "generic_const_exprs", allow(incomplete_features))]
1414
#![warn(missing_docs)]
15-
#![deny(unsafe_op_in_unsafe_fn)]
15+
#![deny(unsafe_op_in_unsafe_fn, clippy::undocumented_unsafe_blocks)]
1616
#![unstable(feature = "portable_simd", issue = "86656")]
1717
//! Portable SIMD module.
1818

crates/core_simd/src/ops.rs

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ where
3333

3434
macro_rules! unsafe_base {
3535
($lhs:ident, $rhs:ident, {$simd_call:ident}, $($_:tt)*) => {
36+
// Safety: $lhs and $rhs are vectors
3637
unsafe { $crate::simd::intrinsics::$simd_call($lhs, $rhs) }
3738
};
3839
}
@@ -49,6 +50,7 @@ macro_rules! unsafe_base {
4950
macro_rules! wrap_bitshift {
5051
($lhs:ident, $rhs:ident, {$simd_call:ident}, $int:ident) => {
5152
#[allow(clippy::suspicious_arithmetic_impl)]
53+
// Safety: $lhs and the bitand result are vectors
5254
unsafe {
5355
$crate::simd::intrinsics::$simd_call(
5456
$lhs,
@@ -91,6 +93,7 @@ macro_rules! int_divrem_guard {
9193
// Nice base case to make it easy to const-fold away the other branch.
9294
$rhs
9395
};
96+
// Safety: $lhs and rhs are vectors
9497
unsafe { $crate::simd::intrinsics::$simd_call($lhs, rhs) }
9598
}
9699
};

crates/core_simd/src/ops/unary.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ macro_rules! neg {
1414
#[inline]
1515
#[must_use = "operator returns a new vector without mutating the input"]
1616
fn neg(self) -> Self::Output {
17+
// Safety: `self` is a signed vector
1718
unsafe { intrinsics::simd_neg(self) }
1819
}
1920
})*

crates/core_simd/src/round.rs

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ macro_rules! implement {
3030
$type: FloatToInt<I>,
3131
I: SimdElement,
3232
{
33+
// Safety: `self` is a vector, and `FloatToInt` ensures the type can be casted to
34+
// an integer.
3335
unsafe { intrinsics::simd_cast(self) }
3436
}
3537
}

0 commit comments

Comments
 (0)