diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 40f7215..9c2eb63 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,9 @@ jobs: - name: install miri run: rustup install nightly && rustup +nightly component add miri - name: miri - run: cargo +nightly miri test --all-features --many-seeds + run: cargo +nightly miri test --all-features + env: + MIRIFLAGS: "-Zmiri-many-seeds" - name: loom run: cargo test --release --lib env: diff --git a/src/queue.rs b/src/queue.rs index 8a92802..ae783f7 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -357,7 +357,7 @@ where dequeuing: DequeuingLength, notify_enqueue: impl Fn(), resize: Option (bool, usize)>, - ) -> Result, TryDequeueError> { + ) -> Result, TryDequeueError> { // If dequeuing length is greater than zero, it means than previous dequeuing is still // ongoing, either because previous `try_dequeue` operation returns pending error, // or because requeuing (after partial draining for example). @@ -450,7 +450,7 @@ where &self, buffer_index: usize, length: NonZeroUsize, - ) -> Option> { + ) -> Option> { for _ in 0..SPIN_LIMIT { // Buffers having been swapped, no more enqueuing can happen, we still need to wait // for ongoing one. They will be finished when the buffer length (updated after @@ -645,7 +645,7 @@ where /// } /// assert_eq!(queue.try_dequeue().unwrap_err(), TryDequeueError::Closed) /// ``` - pub fn try_dequeue(&self) -> Result, TryDequeueError> { + pub fn try_dequeue(&self) -> Result, TryDequeueError> { self.try_dequeue_internal( self.lock_dequeuing()?, || self.notify.notify_enqueue(), @@ -788,7 +788,7 @@ where &self, capacity: impl Into>, insert: Option I>, - ) -> Result, TryDequeueError> + ) -> Result, TryDequeueError> where I: IntoIterator, I::Item: InsertIntoBuffer, diff --git a/src/synchronized.rs b/src/synchronized.rs index 1e5b123..fb3c975 100644 --- a/src/synchronized.rs +++ b/src/synchronized.rs @@ -225,7 +225,7 @@ where fn dequeue_sync( &self, deadline: Option, - ) -> Result, TryDequeueError> { + ) -> Result, TryDequeueError> { loop { if let Some(res) = try_dequeue(self, None) { return res; @@ -268,7 +268,7 @@ where /// queue.close(); /// assert_eq!(task.join().unwrap().unwrap_err(), DequeueError::Closed); /// ``` - pub fn dequeue(&self) -> Result, DequeueError> { + pub fn dequeue(&self) -> Result, DequeueError> { self.dequeue_sync(None).map_err(dequeue_err) } @@ -308,7 +308,7 @@ where pub fn dequeue_timeout( &self, timeout: Duration, - ) -> Result, TryDequeueError> { + ) -> Result, TryDequeueError> { self.dequeue_sync(Some(Instant::now() + timeout)) } @@ -360,7 +360,7 @@ where /// ``` pub async fn dequeue_async( &self, - ) -> Result, DequeueError> { + ) -> Result, DequeueError> { poll_fn(|cx| { if let Some(res) = try_dequeue(self, Some(cx)) { return Poll::Ready(res.map_err(dequeue_err)); diff --git a/src/utils.rs b/src/utils.rs index 9445382..1f1030d 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,9 +1,4 @@ -use core::{ - mem, - mem::MaybeUninit, - ops::{Deref, DerefMut}, - slice, -}; +use core::{mem, mem::MaybeUninit}; pub(crate) fn init_array(default: impl Fn() -> T) -> [T; N] { // SAFETY: common MaybeUninit pattern, used in unstable `MaybeUninit::uninit_array` @@ -12,11 +7,12 @@ pub(crate) fn init_array(default: impl Fn() -> T) -> [T; N] { elem.write(default()); } // SAFETY: all elements have been initialized - // I used `std::mem::transmute_copy` because `transmute` doesn't work here + // I used `core::mem::transmute_copy` because `transmute` doesn't work here // see https://users.rust-lang.org/t/transmuting-a-generic-array/45645 unsafe { mem::transmute_copy(&array) } } +#[cfg(feature = "write")] /// A hack for const-expression-sized array, as discussed here: /// https://users.rust-lang.org/t/is-slice-from-raw-parts-unsound-in-case-of-a-repr-c-struct-with-consecutive-arrays/88368 #[repr(C)] @@ -31,29 +27,38 @@ pub(crate) struct ArrayWithHeaderAndTrailer< trailer: [T; TRAILER_SIZE], } -impl Deref +#[cfg(feature = "write")] +impl core::ops::Deref for ArrayWithHeaderAndTrailer { type Target = [T]; fn deref(&self) -> &Self::Target { // SAFETY: see struct documentation unsafe { - slice::from_raw_parts(self as *const _ as *const T, HEADER_SIZE + N + TRAILER_SIZE) + core::slice::from_raw_parts( + self as *const _ as *const T, + HEADER_SIZE + N + TRAILER_SIZE, + ) } } } -impl DerefMut +#[cfg(feature = "write")] +impl core::ops::DerefMut for ArrayWithHeaderAndTrailer { fn deref_mut(&mut self) -> &mut Self::Target { // SAFETY: see struct documentation unsafe { - slice::from_raw_parts_mut(self as *mut _ as *mut T, HEADER_SIZE + N + TRAILER_SIZE) + core::slice::from_raw_parts_mut( + self as *mut _ as *mut T, + HEADER_SIZE + N + TRAILER_SIZE, + ) } } } +#[cfg(feature = "write")] impl ArrayWithHeaderAndTrailer { @@ -66,6 +71,7 @@ impl } } +#[cfg(feature = "write")] impl Default for ArrayWithHeaderAndTrailer where