From 17449c9561bf8dc8309192dfeba176e34d61e53b Mon Sep 17 00:00:00 2001 From: ZXY Date: Fri, 3 Jul 2026 01:26:32 +0800 Subject: [PATCH] Add #[must_use] to all async Future types Prevents silently dropping futures like tx.push(value) that look synchronous but return an unawaited future. All 8 custom Future types in AsyncProducer/AsyncConsumer traits are annotated. --- async/src/traits/consumer.rs | 4 ++++ async/src/traits/producer.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/async/src/traits/consumer.rs b/async/src/traits/consumer.rs index 570da3e..7cc86e6 100644 --- a/async/src/traits/consumer.rs +++ b/async/src/traits/consumer.rs @@ -129,6 +129,7 @@ pub trait AsyncConsumer: Consumer { /// # Cancel safety /// /// If future is cancelled then no item removed from the ring buffer. +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct PopFuture<'a, A: AsyncConsumer + ?Sized> { owner: &'a mut A, done: bool, @@ -166,6 +167,7 @@ impl Future for PopFuture<'_, A> { /// # Cancel safety /// /// If future is cancelled then slice can be partially filled. +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct PopSliceFuture<'a, 'b, A: AsyncConsumer + ?Sized> where A::Item: Copy, @@ -226,6 +228,7 @@ where /// /// If future is cancelled then `vec` contains items taken from RB before cancellation. #[cfg(feature = "alloc")] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct PopVecFuture<'a, 'b, A: AsyncConsumer + ?Sized> { owner: &'a mut A, vec: Option<&'b mut alloc::vec::Vec>, @@ -275,6 +278,7 @@ impl Future for PopVecFuture<'_, '_, A> { /// # Cancel safety /// /// The future can be safely cancelled. +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct WaitOccupiedFuture<'a, A: AsyncConsumer + ?Sized> { owner: &'a A, count: usize, diff --git a/async/src/traits/producer.rs b/async/src/traits/producer.rs index 46ff0ae..c63d7fb 100644 --- a/async/src/traits/producer.rs +++ b/async/src/traits/producer.rs @@ -136,6 +136,7 @@ pub trait AsyncProducer: Producer { /// # Cancel safety /// /// If future is cancelled no item pushed to the RB. +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct PushFuture<'a, A: AsyncProducer + ?Sized> { owner: &'a mut A, item: Option, @@ -173,6 +174,7 @@ impl Future for PushFuture<'_, A> { /// # Cancel safety /// /// On cancel the slice can be copied partially. +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct PushSliceFuture<'a, 'b, A: AsyncProducer + ?Sized> where A::Item: Copy, @@ -230,6 +232,7 @@ where /// # Cancel safety /// /// If future is cancelled then remaining items are left in iterator. +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct PushIterFuture<'a, A: AsyncProducer + ?Sized, I: Iterator> { owner: &'a mut A, iter: Option>, @@ -278,6 +281,7 @@ impl> PushIterFuture<'_, A, I> { /// # Cancel safety /// /// You can safely cancel this future. +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct WaitVacantFuture<'a, A: AsyncProducer + ?Sized> { owner: &'a A, count: usize,