diff --git a/src/future/future_group.rs b/src/future/future_group.rs index 717c3df..be6935a 100644 --- a/src/future/future_group.rs +++ b/src/future/future_group.rs @@ -301,6 +301,7 @@ impl FutureGroup { 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. diff --git a/src/future/join/array.rs b/src/future/join/array.rs index 5c061bb..00b6915 100644 --- a/src/future/join/array.rs +++ b/src/future/join/array.rs @@ -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. diff --git a/src/future/join/tuple.rs b/src/future/join/tuple.rs index f828780..b797494 100644 --- a/src/future/join/tuple.rs +++ b/src/future/join/tuple.rs @@ -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 diff --git a/src/future/join/vec.rs b/src/future/join/vec.rs index 0bc0980..b17cd79 100644 --- a/src/future/join/vec.rs +++ b/src/future/join/vec.rs @@ -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; @@ -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. @@ -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() { diff --git a/src/future/race/vec.rs b/src/future/race/vec.rs index 80be869..84685bd 100644 --- a/src/future/race/vec.rs +++ b/src/future/race/vec.rs @@ -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; diff --git a/src/future/race_ok/tuple/mod.rs b/src/future/race_ok/tuple/mod.rs index 054ec1d..43dd986 100644 --- a/src/future/race_ok/tuple/mod.rs +++ b/src/future/race_ok/tuple/mod.rs @@ -78,7 +78,7 @@ macro_rules! impl_race_ok_tuple { } } - impl Future for $StructName + impl Future for $StructName where $( $F: Future>, )* ERR: fmt::Debug, @@ -138,7 +138,7 @@ macro_rules! impl_race_ok_tuple { } #[pinned_drop] - impl PinnedDrop for $StructName + impl PinnedDrop for $StructName where $( $F: Future>, )* ERR: fmt::Debug, diff --git a/src/future/race_ok/vec/error.rs b/src/future/race_ok/vec/error.rs index 708b1fa..1e58729 100644 --- a/src/future/race_ok/vec/error.rs +++ b/src/future/race_ok/vec/error.rs @@ -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; diff --git a/src/future/race_ok/vec/mod.rs b/src/future/race_ok/vec/mod.rs index 8448de9..1d11b2e 100644 --- a/src/future/race_ok/vec/mod.rs +++ b/src/future/race_ok/vec/mod.rs @@ -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; @@ -94,7 +95,6 @@ where #[cfg(test)] mod test { - use super::error::AggregateError; use super::*; use alloc::vec; use core::future; diff --git a/src/future/try_join/array.rs b/src/future/try_join/array.rs index cc0269f..7de68d9 100644 --- a/src/future/try_join/array.rs +++ b/src/future/try_join/array.rs @@ -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. diff --git a/src/future/try_join/tuple.rs b/src/future/try_join/tuple.rs index 191089c..8094b48 100644 --- a/src/future/try_join/tuple.rs +++ b/src/future/try_join/tuple.rs @@ -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 @@ -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(())); }) } diff --git a/src/future/try_join/vec.rs b/src/future/try_join/vec.rs index 837b466..86c00b6 100644 --- a/src/future/try_join/vec.rs +++ b/src/future/try_join/vec.rs @@ -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; @@ -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. diff --git a/src/stream/chain/vec.rs b/src/stream/chain/vec.rs index b8152ff..92352db 100644 --- a/src/stream/chain/vec.rs +++ b/src/stream/chain/vec.rs @@ -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}; diff --git a/src/stream/merge/array.rs b/src/stream/merge/array.rs index 934da3b..db3d435 100644 --- a/src/stream/merge/array.rs +++ b/src/stream/merge/array.rs @@ -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. diff --git a/src/stream/merge/tuple.rs b/src/stream/merge/tuple.rs index 2ee119c..d688c18 100644 --- a/src/stream/merge/tuple.rs +++ b/src/stream/merge/tuple.rs @@ -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. diff --git a/src/stream/merge/vec.rs b/src/stream/merge/vec.rs index ebe0a84..86a9f43 100644 --- a/src/stream/merge/vec.rs +++ b/src/stream/merge/vec.rs @@ -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}; @@ -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. diff --git a/src/stream/stream_group.rs b/src/stream/stream_group.rs index 1689255..f0bcab7 100644 --- a/src/stream/stream_group.rs +++ b/src/stream/stream_group.rs @@ -301,6 +301,7 @@ impl StreamGroup { 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. diff --git a/src/stream/zip/array.rs b/src/stream/zip/array.rs index f10ea8a..1a12f4b 100644 --- a/src/stream/zip/array.rs +++ b/src/stream/zip/array.rs @@ -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. @@ -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(array: [MaybeUninit; N]) -> [T; N] { + // SAFETY: + // * The caller guarantees that all elements of the array are initialized + // * `MaybeUninit` 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; @@ -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(array: [MaybeUninit; N]) -> [T; N] { - // SAFETY: - // * The caller guarantees that all elements of the array are initialized - // * `MaybeUninit` 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 -} diff --git a/src/stream/zip/tuple.rs b/src/stream/zip/tuple.rs index a376dcd..6c03e32 100644 --- a/src/stream/zip/tuple.rs +++ b/src/stream/zip/tuple.rs @@ -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. diff --git a/src/stream/zip/vec.rs b/src/stream/zip/vec.rs index 420f8bb..357f785 100644 --- a/src/stream/zip/vec.rs +++ b/src/stream/zip/vec.rs @@ -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; @@ -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. @@ -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(vec: Vec>) -> Vec { + // SAFETY: + // * The caller guarantees that all elements of the vec are initialized + // * `MaybeUninit` 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).read() }; + mem::forget(vec); + ret +} + #[cfg(test)] mod tests { use alloc::vec; @@ -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(vec: Vec>) -> Vec { - // SAFETY: - // * The caller guarantees that all elements of the vec are initialized - // * `MaybeUninit` 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).read() }; - mem::forget(vec); - ret -} diff --git a/src/utils/futures/vec.rs b/src/utils/futures/vec.rs index 459de99..e074287 100644 --- a/src/utils/futures/vec.rs +++ b/src/utils/futures/vec.rs @@ -1,4 +1,6 @@ +#[cfg(all(feature = "alloc", not(feature = "std")))] use alloc::vec::Vec; + use core::{ mem::{self, ManuallyDrop, MaybeUninit}, pin::Pin, diff --git a/src/utils/output/vec.rs b/src/utils/output/vec.rs index bab6e49..6353043 100644 --- a/src/utils/output/vec.rs +++ b/src/utils/output/vec.rs @@ -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. diff --git a/src/utils/pin.rs b/src/utils/pin.rs index cc427fe..5a2a80d 100644 --- a/src/utils/pin.rs +++ b/src/utils/pin.rs @@ -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; diff --git a/src/utils/wakers/array/no_std.rs b/src/utils/wakers/array/no_std.rs index 4113736..447aa8b 100644 --- a/src/utils/wakers/array/no_std.rs +++ b/src/utils/wakers/array/no_std.rs @@ -53,13 +53,13 @@ impl<'a, const N: usize> Deref for ReadinessArrayRef<'a, N> { type Target = ReadinessArray; 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 } } diff --git a/src/utils/wakers/vec/no_std.rs b/src/utils/wakers/vec/no_std.rs index 7bb69eb..3709653 100644 --- a/src/utils/wakers/vec/no_std.rs +++ b/src/utils/wakers/vec/no_std.rs @@ -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 } } diff --git a/src/utils/wakers/vec/waker_vec.rs b/src/utils/wakers/vec/waker_vec.rs index 01f96f2..18d289e 100644 --- a/src/utils/wakers/vec/waker_vec.rs +++ b/src/utils/wakers/vec/waker_vec.rs @@ -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};