Skip to content

Commit e9c4a63

Browse files
authored
Fix new clippy warnings (#18)
1 parent 3bfbe7d commit e9c4a63

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ jobs:
2121
- name: install miri
2222
run: rustup install nightly && rustup +nightly component add miri
2323
- name: miri
24-
run: cargo +nightly miri test --all-features --many-seeds
24+
run: cargo +nightly miri test --all-features
25+
env:
26+
MIRIFLAGS: "-Zmiri-many-seeds"
2527
- name: loom
2628
run: cargo test --release --lib
2729
env:

src/queue.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ where
357357
dequeuing: DequeuingLength,
358358
notify_enqueue: impl Fn(),
359359
resize: Option<impl FnOnce(&mut B) -> (bool, usize)>,
360-
) -> Result<BufferSlice<B, N>, TryDequeueError> {
360+
) -> Result<BufferSlice<'_, B, N>, TryDequeueError> {
361361
// If dequeuing length is greater than zero, it means than previous dequeuing is still
362362
// ongoing, either because previous `try_dequeue` operation returns pending error,
363363
// or because requeuing (after partial draining for example).
@@ -450,7 +450,7 @@ where
450450
&self,
451451
buffer_index: usize,
452452
length: NonZeroUsize,
453-
) -> Option<BufferSlice<B, N>> {
453+
) -> Option<BufferSlice<'_, B, N>> {
454454
for _ in 0..SPIN_LIMIT {
455455
// Buffers having been swapped, no more enqueuing can happen, we still need to wait
456456
// for ongoing one. They will be finished when the buffer length (updated after
@@ -645,7 +645,7 @@ where
645645
/// }
646646
/// assert_eq!(queue.try_dequeue().unwrap_err(), TryDequeueError::Closed)
647647
/// ```
648-
pub fn try_dequeue(&self) -> Result<BufferSlice<B, N>, TryDequeueError> {
648+
pub fn try_dequeue(&self) -> Result<BufferSlice<'_, B, N>, TryDequeueError> {
649649
self.try_dequeue_internal(
650650
self.lock_dequeuing()?,
651651
|| self.notify.notify_enqueue(),
@@ -788,7 +788,7 @@ where
788788
&self,
789789
capacity: impl Into<Option<usize>>,
790790
insert: Option<impl FnOnce() -> I>,
791-
) -> Result<BufferSlice<B, N>, TryDequeueError>
791+
) -> Result<BufferSlice<'_, B, N>, TryDequeueError>
792792
where
793793
I: IntoIterator,
794794
I::Item: InsertIntoBuffer<B>,

src/synchronized.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ where
225225
fn dequeue_sync(
226226
&self,
227227
deadline: Option<Instant>,
228-
) -> Result<BufferSlice<B, SynchronizedNotifier>, TryDequeueError> {
228+
) -> Result<BufferSlice<'_, B, SynchronizedNotifier>, TryDequeueError> {
229229
loop {
230230
if let Some(res) = try_dequeue(self, None) {
231231
return res;
@@ -268,7 +268,7 @@ where
268268
/// queue.close();
269269
/// assert_eq!(task.join().unwrap().unwrap_err(), DequeueError::Closed);
270270
/// ```
271-
pub fn dequeue(&self) -> Result<BufferSlice<B, SynchronizedNotifier>, DequeueError> {
271+
pub fn dequeue(&self) -> Result<BufferSlice<'_, B, SynchronizedNotifier>, DequeueError> {
272272
self.dequeue_sync(None).map_err(dequeue_err)
273273
}
274274

@@ -308,7 +308,7 @@ where
308308
pub fn dequeue_timeout(
309309
&self,
310310
timeout: Duration,
311-
) -> Result<BufferSlice<B, SynchronizedNotifier>, TryDequeueError> {
311+
) -> Result<BufferSlice<'_, B, SynchronizedNotifier>, TryDequeueError> {
312312
self.dequeue_sync(Some(Instant::now() + timeout))
313313
}
314314

@@ -360,7 +360,7 @@ where
360360
/// ```
361361
pub async fn dequeue_async(
362362
&self,
363-
) -> Result<BufferSlice<B, SynchronizedNotifier>, DequeueError> {
363+
) -> Result<BufferSlice<'_, B, SynchronizedNotifier>, DequeueError> {
364364
poll_fn(|cx| {
365365
if let Some(res) = try_dequeue(self, Some(cx)) {
366366
return Poll::Ready(res.map_err(dequeue_err));

src/utils.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
use core::{
2-
mem,
3-
mem::MaybeUninit,
4-
ops::{Deref, DerefMut},
5-
slice,
6-
};
1+
use core::{mem, mem::MaybeUninit};
72

83
pub(crate) fn init_array<T, const N: usize>(default: impl Fn() -> T) -> [T; N] {
94
// SAFETY: common MaybeUninit pattern, used in unstable `MaybeUninit::uninit_array`
@@ -12,11 +7,12 @@ pub(crate) fn init_array<T, const N: usize>(default: impl Fn() -> T) -> [T; N] {
127
elem.write(default());
138
}
149
// SAFETY: all elements have been initialized
15-
// I used `std::mem::transmute_copy` because `transmute` doesn't work here
10+
// I used `core::mem::transmute_copy` because `transmute` doesn't work here
1611
// see https://users.rust-lang.org/t/transmuting-a-generic-array/45645
1712
unsafe { mem::transmute_copy(&array) }
1813
}
1914

15+
#[cfg(feature = "write")]
2016
/// A hack for const-expression-sized array, as discussed here:
2117
/// https://users.rust-lang.org/t/is-slice-from-raw-parts-unsound-in-case-of-a-repr-c-struct-with-consecutive-arrays/88368
2218
#[repr(C)]
@@ -31,29 +27,38 @@ pub(crate) struct ArrayWithHeaderAndTrailer<
3127
trailer: [T; TRAILER_SIZE],
3228
}
3329

34-
impl<T, const HEADER_SIZE: usize, const N: usize, const TRAILER_SIZE: usize> Deref
30+
#[cfg(feature = "write")]
31+
impl<T, const HEADER_SIZE: usize, const N: usize, const TRAILER_SIZE: usize> core::ops::Deref
3532
for ArrayWithHeaderAndTrailer<T, HEADER_SIZE, N, TRAILER_SIZE>
3633
{
3734
type Target = [T];
3835
fn deref(&self) -> &Self::Target {
3936
// SAFETY: see struct documentation
4037
unsafe {
41-
slice::from_raw_parts(self as *const _ as *const T, HEADER_SIZE + N + TRAILER_SIZE)
38+
core::slice::from_raw_parts(
39+
self as *const _ as *const T,
40+
HEADER_SIZE + N + TRAILER_SIZE,
41+
)
4242
}
4343
}
4444
}
4545

46-
impl<T, const HEADER_SIZE: usize, const N: usize, const TRAILER_SIZE: usize> DerefMut
46+
#[cfg(feature = "write")]
47+
impl<T, const HEADER_SIZE: usize, const N: usize, const TRAILER_SIZE: usize> core::ops::DerefMut
4748
for ArrayWithHeaderAndTrailer<T, HEADER_SIZE, N, TRAILER_SIZE>
4849
{
4950
fn deref_mut(&mut self) -> &mut Self::Target {
5051
// SAFETY: see struct documentation
5152
unsafe {
52-
slice::from_raw_parts_mut(self as *mut _ as *mut T, HEADER_SIZE + N + TRAILER_SIZE)
53+
core::slice::from_raw_parts_mut(
54+
self as *mut _ as *mut T,
55+
HEADER_SIZE + N + TRAILER_SIZE,
56+
)
5357
}
5458
}
5559
}
5660

61+
#[cfg(feature = "write")]
5762
impl<T, const HEADER_SIZE: usize, const N: usize, const TRAILER_SIZE: usize>
5863
ArrayWithHeaderAndTrailer<T, HEADER_SIZE, N, TRAILER_SIZE>
5964
{
@@ -66,6 +71,7 @@ impl<T, const HEADER_SIZE: usize, const N: usize, const TRAILER_SIZE: usize>
6671
}
6772
}
6873

74+
#[cfg(feature = "write")]
6975
impl<T, const HEADER_SIZE: usize, const N: usize, const TRAILER_SIZE: usize> Default
7076
for ArrayWithHeaderAndTrailer<T, HEADER_SIZE, N, TRAILER_SIZE>
7177
where

0 commit comments

Comments
 (0)