Skip to content

Commit 7a02909

Browse files
bonziniBennoLossin
authored andcommitted
examples, tests: miscellaneous clippy fixes
Signed-off-by: Paolo Bonzini <[email protected]>
1 parent a0527c8 commit 7a02909

File tree

6 files changed

+20
-10
lines changed

6 files changed

+20
-10
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ unused_attributes = "deny"
3535

3636
[lints.rustdoc]
3737
unescaped_backticks = "deny"
38+
39+
[lints.clippy]
40+
# allow this until the modules in examples/ and tests/ are cleaned up
41+
duplicate_mod = "allow"

examples/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ impl From<AllocError> for Error {
2121
}
2222
}
2323

24+
#[allow(dead_code)]
2425
fn main() {}

examples/mutex.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ impl SpinLock {
4040
}
4141

4242
#[inline]
43+
#[allow(clippy::new_without_default)]
4344
pub const fn new() -> Self {
4445
Self {
4546
inner: AtomicBool::new(false),
@@ -90,6 +91,8 @@ impl<T> CMutex<T> {
9091
park();
9192
sguard = self.spin_lock.acquire();
9293
}
94+
// This does have an effect, as the ListHead inside wait_entry implements Drop!
95+
#[expect(clippy::drop_non_drop)]
9396
drop(wait_entry);
9497
}
9598
self.locked.set(true);
@@ -101,6 +104,7 @@ impl<T> CMutex<T> {
101104
}
102105
}
103106

107+
#[allow(dead_code)]
104108
pub fn get_data_mut(self: Pin<&mut Self>) -> &mut T {
105109
// SAFETY: we have an exclusive reference and thus nobody has access to data.
106110
unsafe { &mut *self.data.get() }
@@ -115,7 +119,7 @@ pub struct CMutexGuard<'a, T> {
115119
_pin: PhantomPinned,
116120
}
117121

118-
impl<'a, T> Drop for CMutexGuard<'a, T> {
122+
impl<T> Drop for CMutexGuard<'_, T> {
119123
#[inline]
120124
fn drop(&mut self) {
121125
let sguard = self.mtx.spin_lock.acquire();
@@ -128,7 +132,7 @@ impl<'a, T> Drop for CMutexGuard<'a, T> {
128132
}
129133
}
130134

131-
impl<'a, T> Deref for CMutexGuard<'a, T> {
135+
impl<T> Deref for CMutexGuard<'_, T> {
132136
type Target = T;
133137

134138
#[inline]
@@ -137,7 +141,7 @@ impl<'a, T> Deref for CMutexGuard<'a, T> {
137141
}
138142
}
139143

140-
impl<'a, T> DerefMut for CMutexGuard<'a, T> {
144+
impl<T> DerefMut for CMutexGuard<'_, T> {
141145
#[inline]
142146
fn deref_mut(&mut self) -> &mut Self::Target {
143147
unsafe { &mut *self.mtx.data.get() }

examples/pthread_mutex.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ mod pthread_mtx {
3838

3939
#[derive(Debug)]
4040
pub enum Error {
41+
#[expect(dead_code)]
4142
IO(std::io::Error),
4243
Alloc,
4344
}
@@ -109,22 +110,22 @@ mod pthread_mtx {
109110
mtx: &'a PThreadMutex<T>,
110111
}
111112

112-
impl<'a, T> Drop for PThreadMutexGuard<'a, T> {
113+
impl<T> Drop for PThreadMutexGuard<'_, T> {
113114
fn drop(&mut self) {
114115
// SAFETY: raw is always initialized
115116
unsafe { libc::pthread_mutex_unlock(self.mtx.raw.get()) };
116117
}
117118
}
118119

119-
impl<'a, T> Deref for PThreadMutexGuard<'a, T> {
120+
impl<T> Deref for PThreadMutexGuard<'_, T> {
120121
type Target = T;
121122

122123
fn deref(&self) -> &Self::Target {
123124
unsafe { &*self.mtx.data.get() }
124125
}
125126
}
126127

127-
impl<'a, T> DerefMut for PThreadMutexGuard<'a, T> {
128+
impl<T> DerefMut for PThreadMutexGuard<'_, T> {
128129
fn deref_mut(&mut self) -> &mut Self::Target {
129130
unsafe { &mut *self.mtx.data.get() }
130131
}

tests/alloc_fail.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#[cfg(feature = "alloc")]
44
use core::alloc::AllocError;
55

6-
use core::convert::Infallible;
76
use pinned_init::*;
87
use std::sync::Arc;
98

tests/ring_buf.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ impl<T, const SIZE: usize> RingBuffer<T, SIZE> {
109109
///
110110
/// TODO
111111
unsafe fn advance(&mut self, ptr: *mut T) -> *mut T {
112-
let ptr = ptr.add(1);
112+
// SAFETY: ptr's offset from buffer is < SIZE
113+
let ptr = unsafe { ptr.add(1) };
113114
let origin: *mut _ = addr_of_mut!(self.buffer);
114115
let origin = origin.cast::<T>();
115116
let offset = unsafe { ptr.offset_from(origin) };
@@ -124,7 +125,7 @@ impl<T, const SIZE: usize> RingBuffer<T, SIZE> {
124125
#[test]
125126
fn on_stack() -> Result<(), Infallible> {
126127
stack_pin_init!(let buf = RingBuffer::<u8, 64>::new());
127-
while let Some(elem) = buf.as_mut().pop() {
128+
if let Some(elem) = buf.as_mut().pop() {
128129
panic!("found in empty buffer!: {elem}");
129130
}
130131
assert!(buf.as_mut().push(10));
@@ -286,6 +287,6 @@ fn with_big_struct() {
286287
Ok(false)
287288
);
288289
for _ in 0..63 {
289-
assert!(matches!(buf.as_mut().pop_no_stack(), Some(_)));
290+
assert!(buf.as_mut().pop_no_stack().is_some());
290291
}
291292
}

0 commit comments

Comments
 (0)