Skip to content

Commit 83768aa

Browse files
committed
Change WakerRef's wake function to panic
1 parent c6345f5 commit 83768aa

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

futures-util/src/task/waker_ref.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(clippy::cast_ptr_alignment)] // clippy is too strict here
22

3-
use super::arc_wake::{ArcWake, clone_arc_raw, wake_arc_raw, wake_by_ref_arc_raw};
3+
use super::arc_wake::{ArcWake, clone_arc_raw, wake_by_ref_arc_raw};
44
use alloc::sync::Arc;
55
use core::marker::PhantomData;
66
use core::ops::Deref;
@@ -44,6 +44,18 @@ impl Deref for WakerRef<'_> {
4444
#[inline]
4545
unsafe fn noop(_data: *const ()) {}
4646

47+
unsafe fn wake_unreachable(_data: *const ()) {
48+
// With only a reference, calling `wake_arc_raw()` would be unsound,
49+
// since the `WakerRef` didn't increment the refcount of the `ArcWake`,
50+
// and `wake_arc_raw` would *decrement* it.
51+
//
52+
// This should never be reachable, since `WakerRef` only provides a `Deref`
53+
// to the inner `Waker`.
54+
//
55+
// Still, safer to panic here than to call `wake_arc_raw`.
56+
unreachable!("WakerRef::wake");
57+
}
58+
4759
/// Creates a reference to a [`Waker`](::std::task::Waker)
4860
/// from a local [`ArcWake`].
4961
///
@@ -62,7 +74,7 @@ where
6274
// Clones of the resulting `RawWaker` will still be dropped normally.
6375
let vtable = &RawWakerVTable::new(
6476
clone_arc_raw::<W>,
65-
wake_arc_raw::<W>,
77+
wake_unreachable,
6678
wake_by_ref_arc_raw::<W>,
6779
noop,
6880
);

0 commit comments

Comments
 (0)