@@ -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 {
@@ -349,8 +353,12 @@ impl<'a> ContextBuilder<'a> {
349353/// of `*waker = new_waker.clone()`, as the former will avoid cloning the waker
350354/// unnecessarily if the two wakers [wake the same task](Self::will_wake).
351355///
356+ /// Constructing a `Waker` from a [`RawWaker`] is unsafe.
357+ /// Implementing the [`Wake`] trait is a safe alternative that requires memory allocation.
358+ ///
352359/// [`Future::poll()`]: core::future::Future::poll
353360/// [`Poll::Pending`]: core::task::Poll::Pending
361+ /// [`Wake`]: ../../alloc/task/trait.Wake.html
354362#[ cfg_attr( not( doc) , repr( transparent) ) ] // work around https://github.com/rust-lang/rust/issues/66401
355363#[ stable( feature = "futures_api" , since = "1.36.0" ) ]
356364pub struct Waker {
@@ -432,9 +440,15 @@ impl Waker {
432440
433441 /// Creates a new `Waker` from [`RawWaker`].
434442 ///
443+ /// # Safety
444+ ///
435445 /// The behavior of the returned `Waker` is undefined if the contract defined
436446 /// in [`RawWaker`]'s and [`RawWakerVTable`]'s documentation is not upheld.
437- /// Therefore this method is unsafe.
447+ ///
448+ /// (Authors wishing to avoid unsafe code may implement the [`Wake`] trait instead, at the
449+ /// cost of a required heap allocation.)
450+ ///
451+ /// [`Wake`]: ../../alloc/task/trait.Wake.html
438452 #[ inline]
439453 #[ must_use]
440454 #[ stable( feature = "futures_api" , since = "1.36.0" ) ]
0 commit comments