Skip to content

Commit f7b0358

Browse files
Sprinkle the crate with #[must_use]
1 parent 690184a commit f7b0358

File tree

7 files changed

+90
-0
lines changed

7 files changed

+90
-0
lines changed

crates/core_simd/src/comparisons.rs

+6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ where
88
{
99
/// Test if each lane is equal to the corresponding lane in `other`.
1010
#[inline]
11+
#[must_use = "method returns a new mask and does not mutate the original value"]
1112
pub fn lanes_eq(self, other: Self) -> Mask<T::Mask, LANES> {
1213
unsafe { Mask::from_int_unchecked(intrinsics::simd_eq(self, other)) }
1314
}
1415

1516
/// Test if each lane is not equal to the corresponding lane in `other`.
1617
#[inline]
18+
#[must_use = "method returns a new mask and does not mutate the original value"]
1719
pub fn lanes_ne(self, other: Self) -> Mask<T::Mask, LANES> {
1820
unsafe { Mask::from_int_unchecked(intrinsics::simd_ne(self, other)) }
1921
}
@@ -26,24 +28,28 @@ where
2628
{
2729
/// Test if each lane is less than the corresponding lane in `other`.
2830
#[inline]
31+
#[must_use = "method returns a new mask and does not mutate the original value"]
2932
pub fn lanes_lt(self, other: Self) -> Mask<T::Mask, LANES> {
3033
unsafe { Mask::from_int_unchecked(intrinsics::simd_lt(self, other)) }
3134
}
3235

3336
/// Test if each lane is greater than the corresponding lane in `other`.
3437
#[inline]
38+
#[must_use = "method returns a new mask and does not mutate the original value"]
3539
pub fn lanes_gt(self, other: Self) -> Mask<T::Mask, LANES> {
3640
unsafe { Mask::from_int_unchecked(intrinsics::simd_gt(self, other)) }
3741
}
3842

3943
/// Test if each lane is less than or equal to the corresponding lane in `other`.
4044
#[inline]
45+
#[must_use = "method returns a new mask and does not mutate the original value"]
4146
pub fn lanes_le(self, other: Self) -> Mask<T::Mask, LANES> {
4247
unsafe { Mask::from_int_unchecked(intrinsics::simd_le(self, other)) }
4348
}
4449

4550
/// Test if each lane is greater than or equal to the corresponding lane in `other`.
4651
#[inline]
52+
#[must_use = "method returns a new mask and does not mutate the original value"]
4753
pub fn lanes_ge(self, other: Self) -> Mask<T::Mask, LANES> {
4854
unsafe { Mask::from_int_unchecked(intrinsics::simd_ge(self, other)) }
4955
}

crates/core_simd/src/masks.rs

+24
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ where
129129
/// # Safety
130130
/// All lanes must be either 0 or -1.
131131
#[inline]
132+
#[must_use = "method returns a new mask and does not mutate the original value"]
132133
pub unsafe fn from_int_unchecked(value: Simd<T, LANES>) -> Self {
133134
unsafe { Self(mask_impl::Mask::from_int_unchecked(value)) }
134135
}
@@ -139,6 +140,7 @@ where
139140
/// # Panics
140141
/// Panics if any lane is not 0 or -1.
141142
#[inline]
143+
#[must_use = "method returns a new mask and does not mutate the original value"]
142144
pub fn from_int(value: Simd<T, LANES>) -> Self {
143145
assert!(T::valid(value), "all values must be either 0 or -1",);
144146
unsafe { Self::from_int_unchecked(value) }
@@ -147,6 +149,7 @@ where
147149
/// Converts the mask to a vector of integers, where 0 represents `false` and -1
148150
/// represents `true`.
149151
#[inline]
152+
#[must_use = "method returns a new vector and does not mutate the original value"]
150153
pub fn to_int(self) -> Simd<T, LANES> {
151154
self.0.to_int()
152155
}
@@ -156,6 +159,7 @@ where
156159
/// # Safety
157160
/// `lane` must be less than `LANES`.
158161
#[inline]
162+
#[must_use = "method returns a new bool and does not mutate the original value"]
159163
pub unsafe fn test_unchecked(&self, lane: usize) -> bool {
160164
unsafe { self.0.test_unchecked(lane) }
161165
}
@@ -165,6 +169,7 @@ where
165169
/// # Panics
166170
/// Panics if `lane` is greater than or equal to the number of lanes in the vector.
167171
#[inline]
172+
#[must_use = "method returns a new bool and does not mutate the original value"]
168173
pub fn test(&self, lane: usize) -> bool {
169174
assert!(lane < LANES, "lane index out of range");
170175
unsafe { self.test_unchecked(lane) }
@@ -195,24 +200,30 @@ where
195200

196201
/// Convert this mask to a bitmask, with one bit set per lane.
197202
#[cfg(feature = "generic_const_exprs")]
203+
#[inline]
204+
#[must_use = "method returns a new array and does not mutate the original value"]
198205
pub fn to_bitmask(self) -> [u8; LaneCount::<LANES>::BITMASK_LEN] {
199206
self.0.to_bitmask()
200207
}
201208

202209
/// Convert a bitmask to a mask.
203210
#[cfg(feature = "generic_const_exprs")]
211+
#[inline]
212+
#[must_use = "method returns a new mask and does not mutate the original value"]
204213
pub fn from_bitmask(bitmask: [u8; LaneCount::<LANES>::BITMASK_LEN]) -> Self {
205214
Self(mask_impl::Mask::from_bitmask(bitmask))
206215
}
207216

208217
/// Returns true if any lane is set, or false otherwise.
209218
#[inline]
219+
#[must_use = "method returns a new bool and does not mutate the original value"]
210220
pub fn any(self) -> bool {
211221
self.0.any()
212222
}
213223

214224
/// Returns true if all lanes are set, or false otherwise.
215225
#[inline]
226+
#[must_use = "method returns a new bool and does not mutate the original value"]
216227
pub fn all(self) -> bool {
217228
self.0.all()
218229
}
@@ -245,6 +256,7 @@ where
245256
LaneCount<LANES>: SupportedLaneCount,
246257
{
247258
#[inline]
259+
#[must_use = "method returns a defaulted mask with all lanes set to false (0)"]
248260
fn default() -> Self {
249261
Self::splat(false)
250262
}
@@ -256,6 +268,7 @@ where
256268
LaneCount<LANES>: SupportedLaneCount,
257269
{
258270
#[inline]
271+
#[must_use = "method returns a new bool and does not mutate the original value"]
259272
fn eq(&self, other: &Self) -> bool {
260273
self.0 == other.0
261274
}
@@ -267,6 +280,7 @@ where
267280
LaneCount<LANES>: SupportedLaneCount,
268281
{
269282
#[inline]
283+
#[must_use = "method returns a new Ordering and does not mutate the original value"]
270284
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
271285
self.0.partial_cmp(&other.0)
272286
}
@@ -291,6 +305,7 @@ where
291305
{
292306
type Output = Self;
293307
#[inline]
308+
#[must_use = "method returns a new mask and does not mutate the original value"]
294309
fn bitand(self, rhs: Self) -> Self {
295310
Self(self.0 & rhs.0)
296311
}
@@ -303,6 +318,7 @@ where
303318
{
304319
type Output = Self;
305320
#[inline]
321+
#[must_use = "method returns a new mask and does not mutate the original value"]
306322
fn bitand(self, rhs: bool) -> Self {
307323
self & Self::splat(rhs)
308324
}
@@ -315,6 +331,7 @@ where
315331
{
316332
type Output = Mask<T, LANES>;
317333
#[inline]
334+
#[must_use = "method returns a new mask and does not mutate the original value"]
318335
fn bitand(self, rhs: Mask<T, LANES>) -> Mask<T, LANES> {
319336
Mask::splat(self) & rhs
320337
}
@@ -327,6 +344,7 @@ where
327344
{
328345
type Output = Self;
329346
#[inline]
347+
#[must_use = "method returns a new mask and does not mutate the original value"]
330348
fn bitor(self, rhs: Self) -> Self {
331349
Self(self.0 | rhs.0)
332350
}
@@ -339,6 +357,7 @@ where
339357
{
340358
type Output = Self;
341359
#[inline]
360+
#[must_use = "method returns a new mask and does not mutate the original value"]
342361
fn bitor(self, rhs: bool) -> Self {
343362
self | Self::splat(rhs)
344363
}
@@ -351,6 +370,7 @@ where
351370
{
352371
type Output = Mask<T, LANES>;
353372
#[inline]
373+
#[must_use = "method returns a new mask and does not mutate the original value"]
354374
fn bitor(self, rhs: Mask<T, LANES>) -> Mask<T, LANES> {
355375
Mask::splat(self) | rhs
356376
}
@@ -363,6 +383,7 @@ where
363383
{
364384
type Output = Self;
365385
#[inline]
386+
#[must_use = "method returns a new mask and does not mutate the original value"]
366387
fn bitxor(self, rhs: Self) -> Self::Output {
367388
Self(self.0 ^ rhs.0)
368389
}
@@ -375,6 +396,7 @@ where
375396
{
376397
type Output = Self;
377398
#[inline]
399+
#[must_use = "method returns a new mask and does not mutate the original value"]
378400
fn bitxor(self, rhs: bool) -> Self::Output {
379401
self ^ Self::splat(rhs)
380402
}
@@ -387,6 +409,7 @@ where
387409
{
388410
type Output = Mask<T, LANES>;
389411
#[inline]
412+
#[must_use = "method returns a new mask and does not mutate the original value"]
390413
fn bitxor(self, rhs: Mask<T, LANES>) -> Self::Output {
391414
Mask::splat(self) ^ rhs
392415
}
@@ -399,6 +422,7 @@ where
399422
{
400423
type Output = Mask<T, LANES>;
401424
#[inline]
425+
#[must_use = "method returns a new mask and does not mutate the original value"]
402426
fn not(self) -> Self::Output {
403427
Self(!self.0)
404428
}

crates/core_simd/src/masks/bitmask.rs

+13
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ where
7474
LaneCount<LANES>: SupportedLaneCount,
7575
{
7676
#[inline]
77+
#[must_use = "method returns a new mask and does not mutate the original value"]
7778
pub fn splat(value: bool) -> Self {
7879
let mut mask = <LaneCount<LANES> as SupportedLaneCount>::BitMask::default();
7980
if value {
@@ -88,6 +89,7 @@ where
8889
}
8990

9091
#[inline]
92+
#[must_use = "method returns a new bool and does not mutate the original value"]
9193
pub unsafe fn test_unchecked(&self, lane: usize) -> bool {
9294
(self.0.as_ref()[lane / 8] >> (lane % 8)) & 0x1 > 0
9395
}
@@ -100,6 +102,7 @@ where
100102
}
101103

102104
#[inline]
105+
#[must_use = "method returns a new vector and does not mutate the original value"]
103106
pub fn to_int(self) -> Simd<T, LANES> {
104107
unsafe {
105108
crate::intrinsics::simd_select_bitmask(
@@ -111,25 +114,29 @@ where
111114
}
112115

113116
#[inline]
117+
#[must_use = "method returns a new mask and does not mutate the original value"]
114118
pub unsafe fn from_int_unchecked(value: Simd<T, LANES>) -> Self {
115119
unsafe { Self(crate::intrinsics::simd_bitmask(value), PhantomData) }
116120
}
117121

118122
#[cfg(feature = "generic_const_exprs")]
119123
#[inline]
124+
#[must_use = "method returns a new array and does not mutate the original value"]
120125
pub fn to_bitmask(self) -> [u8; LaneCount::<LANES>::BITMASK_LEN] {
121126
// Safety: these are the same type and we are laundering the generic
122127
unsafe { core::mem::transmute_copy(&self.0) }
123128
}
124129

125130
#[cfg(feature = "generic_const_exprs")]
126131
#[inline]
132+
#[must_use = "method returns a new mask and does not mutate the original value"]
127133
pub fn from_bitmask(bitmask: [u8; LaneCount::<LANES>::BITMASK_LEN]) -> Self {
128134
// Safety: these are the same type and we are laundering the generic
129135
Self(unsafe { core::mem::transmute_copy(&bitmask) }, PhantomData)
130136
}
131137

132138
#[inline]
139+
#[must_use = "method returns a new mask and does not mutate the original value"]
133140
pub fn convert<U>(self) -> Mask<U, LANES>
134141
where
135142
U: MaskElement,
@@ -138,11 +145,13 @@ where
138145
}
139146

140147
#[inline]
148+
#[must_use = "method returns a new bool and does not mutate the original value"]
141149
pub fn any(self) -> bool {
142150
self != Self::splat(false)
143151
}
144152

145153
#[inline]
154+
#[must_use = "method returns a new bool and does not mutate the original value"]
146155
pub fn all(self) -> bool {
147156
self == Self::splat(true)
148157
}
@@ -156,6 +165,7 @@ where
156165
{
157166
type Output = Self;
158167
#[inline]
168+
#[must_use = "method returns a new mask and does not mutate the original value"]
159169
fn bitand(mut self, rhs: Self) -> Self {
160170
for (l, r) in self.0.as_mut().iter_mut().zip(rhs.0.as_ref().iter()) {
161171
*l &= r;
@@ -172,6 +182,7 @@ where
172182
{
173183
type Output = Self;
174184
#[inline]
185+
#[must_use = "method returns a new mask and does not mutate the original value"]
175186
fn bitor(mut self, rhs: Self) -> Self {
176187
for (l, r) in self.0.as_mut().iter_mut().zip(rhs.0.as_ref().iter()) {
177188
*l |= r;
@@ -187,6 +198,7 @@ where
187198
{
188199
type Output = Self;
189200
#[inline]
201+
#[must_use = "method returns a new mask and does not mutate the original value"]
190202
fn bitxor(mut self, rhs: Self) -> Self::Output {
191203
for (l, r) in self.0.as_mut().iter_mut().zip(rhs.0.as_ref().iter()) {
192204
*l ^= r;
@@ -202,6 +214,7 @@ where
202214
{
203215
type Output = Self;
204216
#[inline]
217+
#[must_use = "method returns a new mask and does not mutate the original value"]
205218
fn not(mut self) -> Self::Output {
206219
for x in self.0.as_mut() {
207220
*x = !*x;

0 commit comments

Comments
 (0)