Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy warnings #170

Merged
merged 7 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/future/future_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ impl<F: Future> FutureGroup<F> {
for index in this.keys.iter().cloned() {
if states[index].is_pending() && readiness.clear_ready(index) {
// unlock readiness so we don't deadlock when polling
#[allow(clippy::drop_non_drop)]
drop(readiness);

// Obtain the intermediate waker.
Expand Down
1 change: 1 addition & 0 deletions src/future/join/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ where
for (i, mut fut) in this.futures.iter().enumerate() {
if this.state[i].is_pending() && readiness.clear_ready(i) {
// unlock readiness so we don't deadlock when polling
#[allow(clippy::drop_non_drop)]
drop(readiness);

// Obtain the intermediate waker.
Expand Down
1 change: 1 addition & 0 deletions src/future/join/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ macro_rules! impl_join_tuple {
}

// unlock readiness so we don't deadlock when polling
#[allow(clippy::drop_non_drop)]
drop(readiness);

// obtain the intermediate waker
Expand Down
5 changes: 3 additions & 2 deletions src/future/join/vec.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use super::Join as JoinTrait;
use crate::utils::{FutureVec, OutputVec, PollVec, WakerVec};

#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::vec::Vec;

use core::fmt;
use core::future::{Future, IntoFuture};
use core::mem::ManuallyDrop;
Expand Down Expand Up @@ -98,6 +100,7 @@ where
for (i, mut fut) in futures.iter().enumerate() {
if states[i].is_pending() && readiness.clear_ready(i) {
// unlock readiness so we don't deadlock when polling
#[allow(clippy::drop_non_drop)]
drop(readiness);

// Obtain the intermediate waker.
Expand Down Expand Up @@ -178,8 +181,6 @@ mod test {
use alloc::sync::Arc;
use alloc::vec;
use core::future;
use core::future::Future;
use core::task::Context;

#[test]
fn smoke() {
Expand Down
2 changes: 2 additions & 0 deletions src/future/race/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use crate::utils::{self, Indexer};

use super::Race as RaceTrait;

#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::vec::Vec;

use core::fmt;
use core::future::{Future, IntoFuture};
use core::pin::Pin;
Expand Down
4 changes: 2 additions & 2 deletions src/future/race_ok/tuple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ macro_rules! impl_race_ok_tuple {
}
}

impl<T, ERR, $($F: Future),*> Future for $StructName<T, ERR, $($F),*>
impl<T, ERR, $($F),*> Future for $StructName<T, ERR, $($F),*>
where
$( $F: Future<Output = Result<T, ERR>>, )*
ERR: fmt::Debug,
Expand Down Expand Up @@ -138,7 +138,7 @@ macro_rules! impl_race_ok_tuple {
}

#[pinned_drop]
impl<T, ERR, $($F: Future,)*> PinnedDrop for $StructName<T, ERR, $($F,)*>
impl<T, ERR, $($F,)*> PinnedDrop for $StructName<T, ERR, $($F,)*>
where
$( $F: Future<Output = Result<T, ERR>>, )*
ERR: fmt::Debug,
Expand Down
2 changes: 2 additions & 0 deletions src/future/race_ok/vec/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::vec::Vec;

use core::fmt;
use core::ops::Deref;
use core::ops::DerefMut;
Expand Down
6 changes: 3 additions & 3 deletions src/future/race_ok/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use super::RaceOk as RaceOkTrait;
use crate::utils::iter_pin_mut;
use crate::utils::MaybeDone;

use alloc::boxed::Box;
use alloc::vec::Vec;
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::{boxed::Box, vec::Vec};

use core::fmt;
use core::future::{Future, IntoFuture};
use core::mem;
Expand Down Expand Up @@ -94,7 +95,6 @@ where

#[cfg(test)]
mod test {
use super::error::AggregateError;
use super::*;
use alloc::vec;
use core::future;
Expand Down
1 change: 1 addition & 0 deletions src/future/try_join/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ where
for (i, mut fut) in this.futures.iter().enumerate() {
if this.state[i].is_pending() && readiness.clear_ready(i) {
// unlock readiness so we don't deadlock when polling
#[allow(clippy::drop_non_drop)]
drop(readiness);

// Obtain the intermediate waker.
Expand Down
3 changes: 2 additions & 1 deletion src/future/try_join/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ macro_rules! impl_try_join_tuple {
}

// unlock readiness so we don't deadlock when polling
#[allow(clippy::drop_non_drop)]
drop(readiness);

// obtain the intermediate waker
Expand Down Expand Up @@ -354,7 +355,7 @@ mod test {
let res: Result<(_, char), ()> = (future::ready(Ok("hello")), future::ready(Err(())))
.try_join()
.await;
assert_eq!(res.unwrap_err(), ());
assert_eq!(res, Err(()));
})
}

Expand Down
3 changes: 3 additions & 0 deletions src/future/try_join/vec.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use super::TryJoin as TryJoinTrait;
use crate::utils::{FutureVec, OutputVec, PollVec, WakerVec};

#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::vec::Vec;

use core::fmt;
use core::future::{Future, IntoFuture};
use core::mem::ManuallyDrop;
Expand Down Expand Up @@ -106,6 +108,7 @@ where
for (i, mut fut) in this.futures.iter().enumerate() {
if this.state[i].is_pending() && readiness.clear_ready(i) {
// unlock readiness so we don't deadlock when polling
#[allow(clippy::drop_non_drop)]
drop(readiness);

// Obtain the intermediate waker.
Expand Down
2 changes: 2 additions & 0 deletions src/stream/chain/vec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::vec::Vec;

use core::fmt;
use core::pin::Pin;
use core::task::{Context, Poll};
Expand Down
1 change: 1 addition & 0 deletions src/stream/merge/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ where
}

// unlock readiness so we don't deadlock when polling
#[allow(clippy::drop_non_drop)]
drop(readiness);

// Obtain the intermediate waker.
Expand Down
1 change: 1 addition & 0 deletions src/stream/merge/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ macro_rules! impl_merge_tuple {
}

// unlock readiness so we don't deadlock when polling
#[allow(clippy::drop_non_drop)]
drop(readiness);

// Obtain the intermediate waker.
Expand Down
3 changes: 3 additions & 0 deletions src/stream/merge/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use super::Merge as MergeTrait;
use crate::stream::IntoStream;
use crate::utils::{self, Indexer, PollVec, WakerVec};

#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::vec::Vec;

use core::fmt;
use core::pin::Pin;
use core::task::{Context, Poll};
Expand Down Expand Up @@ -79,6 +81,7 @@ where
}

// unlock readiness so we don't deadlock when polling
#[allow(clippy::drop_non_drop)]
drop(readiness);

// Obtain the intermediate waker.
Expand Down
1 change: 1 addition & 0 deletions src/stream/stream_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ impl<S: Stream> StreamGroup<S> {
for index in this.keys.iter().cloned() {
if states[index].is_pending() && readiness.clear_ready(index) {
// unlock readiness so we don't deadlock when polling
#[allow(clippy::drop_non_drop)]
drop(readiness);

// Obtain the intermediate waker.
Expand Down
29 changes: 15 additions & 14 deletions src/stream/zip/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ where
}

// unlock readiness so we don't deadlock when polling
#[allow(clippy::drop_non_drop)]
drop(readiness);

// Obtain the intermediate waker.
Expand Down Expand Up @@ -154,6 +155,20 @@ where
}
}

// Inlined version of the unstable `MaybeUninit::array_assume_init` feature.
// FIXME: replace with `utils::array_assume_init`
unsafe fn array_assume_init<T, const N: usize>(array: [MaybeUninit<T>; N]) -> [T; N] {
// SAFETY:
// * The caller guarantees that all elements of the array are initialized
// * `MaybeUninit<T>` and T are guaranteed to have the same layout
// * `MaybeUninit` does not drop, so there are no double-frees
// And thus the conversion is safe
let ret = unsafe { (&array as *const _ as *const [T; N]).read() };
#[allow(clippy::forget_non_drop)]
mem::forget(array);
ret
}

#[cfg(test)]
mod tests {
use crate::stream::Zip;
Expand All @@ -175,17 +190,3 @@ mod tests {
})
}
}

// Inlined version of the unstable `MaybeUninit::array_assume_init` feature.
// FIXME: replace with `utils::array_assume_init`
unsafe fn array_assume_init<T, const N: usize>(array: [MaybeUninit<T>; N]) -> [T; N] {
// SAFETY:
// * The caller guarantees that all elements of the array are initialized
// * `MaybeUninit<T>` and T are guaranteed to have the same layout
// * `MaybeUninit` does not drop, so there are no double-frees
// And thus the conversion is safe
let ret = unsafe { (&array as *const _ as *const [T; N]).read() };
#[allow(clippy::forget_non_drop)]
mem::forget(array);
ret
}
1 change: 1 addition & 0 deletions src/stream/zip/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ macro_rules! impl_zip_for_tuple {
}

// unlock readiness so we don't deadlock when polling
#[allow(clippy::drop_non_drop)]
drop(readiness);

// Obtain the intermediate waker.
Expand Down
30 changes: 16 additions & 14 deletions src/stream/zip/vec.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use super::Zip as ZipTrait;
use crate::stream::IntoStream;
use crate::utils::{self, PollVec, WakerVec};

#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::vec::Vec;

use core::fmt;
use core::mem;
use core::mem::MaybeUninit;
Expand Down Expand Up @@ -83,6 +84,7 @@ where
}

// unlock readiness so we don't deadlock when polling
#[allow(clippy::drop_non_drop)]
drop(readiness);

// Obtain the intermediate waker.
Expand Down Expand Up @@ -158,6 +160,19 @@ where
}
}

// Inlined version of the unstable `MaybeUninit::array_assume_init` feature.
// FIXME: replace with `utils::array_assume_init`
unsafe fn vec_assume_init<T>(vec: Vec<MaybeUninit<T>>) -> Vec<T> {
// SAFETY:
// * The caller guarantees that all elements of the vec are initialized
// * `MaybeUninit<T>` and T are guaranteed to have the same layout
// * `MaybeUninit` does not drop, so there are no double-frees
// And thus the conversion is safe
let ret = unsafe { (&vec as *const _ as *const Vec<T>).read() };
mem::forget(vec);
ret
}

#[cfg(test)]
mod tests {
use alloc::vec;
Expand All @@ -181,16 +196,3 @@ mod tests {
})
}
}

// Inlined version of the unstable `MaybeUninit::array_assume_init` feature.
// FIXME: replace with `utils::array_assume_init`
unsafe fn vec_assume_init<T>(vec: Vec<MaybeUninit<T>>) -> Vec<T> {
// SAFETY:
// * The caller guarantees that all elements of the vec are initialized
// * `MaybeUninit<T>` and T are guaranteed to have the same layout
// * `MaybeUninit` does not drop, so there are no double-frees
// And thus the conversion is safe
let ret = unsafe { (&vec as *const _ as *const Vec<T>).read() };
mem::forget(vec);
ret
}
2 changes: 2 additions & 0 deletions src/utils/futures/vec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::vec::Vec;

use core::{
mem::{self, ManuallyDrop, MaybeUninit},
pin::Pin,
Expand Down
5 changes: 3 additions & 2 deletions src/utils/output/vec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use alloc::vec;
use alloc::vec::Vec;
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::{vec, vec::Vec};

use core::mem::{self, MaybeUninit};

/// A contiguous vector of uninitialized data.
Expand Down
3 changes: 2 additions & 1 deletion src/utils/pin.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[cfg(feature = "alloc")]
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::vec::Vec;

use core::pin::Pin;
use core::slice::SliceIndex;

Expand Down
4 changes: 2 additions & 2 deletions src/utils/wakers/array/no_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ impl<'a, const N: usize> Deref for ReadinessArrayRef<'a, N> {
type Target = ReadinessArray<N>;

fn deref(&self) -> &Self::Target {
&self.inner
self.inner
}
}

impl<'a, const N: usize> DerefMut for ReadinessArrayRef<'a, N> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
self.inner
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/wakers/vec/no_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ impl<'a> Deref for ReadinessVecRef<'a> {
type Target = ReadinessVec;

fn deref(&self) -> &Self::Target {
&self.inner
self.inner
}
}

impl<'a> DerefMut for ReadinessVecRef<'a> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
self.inner
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/utils/wakers/vec/waker_vec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use alloc::sync::Arc;
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::vec::Vec;

use alloc::sync::Arc;
use core::task::Waker;
use std::sync::{Mutex, MutexGuard};

Expand Down
Loading