Skip to content

Commit d7c677a

Browse files
committed
cmov: additional clippy lints
Enables the following and fixes violations if any: - `clippy::ref_as_ptr` - `clippy::return_self_not_must_use` - `clippy::semicolon_if_nothing_returned`
1 parent f1dfe41 commit d7c677a

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

cmov/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
clippy::mod_module_files,
1616
clippy::panic,
1717
clippy::panic_in_result_fn,
18+
clippy::ref_as_ptr,
19+
clippy::return_self_not_must_use,
20+
clippy::semicolon_if_nothing_returned,
1821
clippy::std_instead_of_alloc,
1922
clippy::std_instead_of_core,
2023
clippy::unwrap_used,
@@ -50,7 +53,7 @@ pub trait Cmov {
5053
/// Moves `value` to `self` in constant-time if `condition` is equal to zero.
5154
fn cmovz(&mut self, value: &Self, condition: Condition) {
5255
let nz = masknz!(condition: Condition);
53-
self.cmovnz(value, !nz)
56+
self.cmovnz(value, !nz);
5457
}
5558
}
5659

cmov/src/slice.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::{Cmov, CmovEq, Condition};
44
use core::{
55
ops::{BitOrAssign, Shl},
6-
slice,
6+
ptr, slice,
77
};
88

99
// Uses 64-bit words on 64-bit targets, 32-bit everywhere else
@@ -267,9 +267,9 @@ unsafe fn cast_slice<T, U>(slice: &[T]) -> &[U] {
267267
// SAFETY:
268268
// - Slices are of same-sized/aligned types as asserted above.
269269
// - It's up to the caller to ensure the pointer cast from `T` to `U` itself is valid.
270-
#[allow(trivial_casts, unsafe_code)]
270+
#[allow(unsafe_code)]
271271
unsafe {
272-
&*((slice as *const [T]) as *const [U])
272+
&*(ptr::from_ref::<[T]>(slice) as *const [U])
273273
}
274274
}
275275

@@ -287,9 +287,9 @@ unsafe fn cast_slice_mut<T, U>(slice: &mut [T]) -> &mut [U] {
287287
// SAFETY:
288288
// - Slices are of same-sized/aligned types as asserted above.
289289
// - It's up to the caller to ensure the pointer cast from `T` to `U` itself is valid.
290-
#[allow(trivial_casts, unsafe_code)]
290+
#[allow(unsafe_code)]
291291
unsafe {
292-
&mut *((slice as *mut [T]) as *mut [U])
292+
&mut *(ptr::from_mut::<[T]>(slice) as *mut [U])
293293
}
294294
}
295295

0 commit comments

Comments
 (0)