@@ -9,10 +9,14 @@ use crate::ptr;
99/// A `RawWaker` allows the implementor of a task executor to create a [`Waker`]
1010/// or a [`LocalWaker`] which provides customized wakeup behavior.
1111///
12- /// [vtable]: https://en.wikipedia.org/wiki/Virtual_method_table
13- ///
1412/// It consists of a data pointer and a [virtual function pointer table (vtable)][vtable]
1513/// that customizes the behavior of the `RawWaker`.
14+ ///
15+ /// `RawWaker`s are unsafe to use.
16+ /// Implementing the [`Wake`] trait is a safe alternative that requires memory allocation.
17+ ///
18+ /// [vtable]: https://en.wikipedia.org/wiki/Virtual_method_table
19+ /// [`Wake`]: ../../alloc/task/trait.Wake.html
1620#[ derive( PartialEq , Debug ) ]
1721#[ stable( feature = "futures_api" , since = "1.36.0" ) ]
1822pub struct RawWaker {
@@ -355,8 +359,12 @@ impl<'a> ContextBuilder<'a> {
355359/// of `*waker = new_waker.clone()`, as the former will avoid cloning the waker
356360/// unnecessarily if the two wakers [wake the same task](Self::will_wake).
357361///
362+ /// Constructing a `Waker` from a [`RawWaker`] is unsafe.
363+ /// Implementing the [`Wake`] trait is a safe alternative that requires memory allocation.
364+ ///
358365/// [`Future::poll()`]: core::future::Future::poll
359366/// [`Poll::Pending`]: core::task::Poll::Pending
367+ /// [`Wake`]: ../../alloc/task/trait.Wake.html
360368#[ cfg_attr( not( doc) , repr( transparent) ) ] // work around https://github.com/rust-lang/rust/issues/66401
361369#[ stable( feature = "futures_api" , since = "1.36.0" ) ]
362370pub struct Waker {
@@ -438,9 +446,15 @@ impl Waker {
438446
439447 /// Creates a new `Waker` from [`RawWaker`].
440448 ///
449+ /// # Safety
450+ ///
441451 /// The behavior of the returned `Waker` is undefined if the contract defined
442452 /// in [`RawWaker`]'s and [`RawWakerVTable`]'s documentation is not upheld.
443- /// Therefore this method is unsafe.
453+ ///
454+ /// (Authors wishing to avoid unsafe code may implement the [`Wake`] trait instead, at the
455+ /// cost of a required heap allocation.)
456+ ///
457+ /// [`Wake`]: ../../alloc/task/trait.Wake.html
444458 #[ inline]
445459 #[ must_use]
446460 #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
0 commit comments