Skip to content

Commit 647a951

Browse files
committed
Auto merge of #60128 - jimblandy:futures-doc-fix, r=withoutboats
Doc fixes for core::future::Future. Fixed outdated reference to `waker` argument; now futures are passed a `Context`, from which one can obtain a `waker`. Cleaned up explanation of what happens when you call `poll` on a completed future. It doesn't make sense to say that `poll` implementations can't cause memory unsafety; no safe function is ever allowed to cause memory unsafety, so why mention it here? It seems like the intent is to say that the `Future` trait doesn't say what the consequences of excess polls will be, and they might be bad; but that the usual constraints that Rust imposes on any non-`unsafe` function still apply. It's also oddly specific to say 'memory corruption' instead of just 'undefined behavior'; UB is a bit jargony, so the text should provide examples.
2 parents 7754865 + f8f02de commit 647a951

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/libcore/future/future.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ use crate::task::{Context, Poll};
1818
/// The core method of future, `poll`, *attempts* to resolve the future into a
1919
/// final value. This method does not block if the value is not ready. Instead,
2020
/// the current task is scheduled to be woken up when it's possible to make
21-
/// further progress by `poll`ing again. The wake up is performed using
22-
/// the `waker` argument of the `poll()` method, which is a handle for waking
23-
/// up the current task.
21+
/// further progress by `poll`ing again. The `context` passed to the `poll`
22+
/// method can provide a `Waker`, which is a handle for waking up the current
23+
/// task.
2424
///
2525
/// When using a future, you generally won't call `poll` directly, but instead
2626
/// `await!` the value.
@@ -49,13 +49,13 @@ pub trait Future {
4949
/// For example, a future waiting for a socket to become
5050
/// readable would call `.clone()` on the [`Waker`] and store it.
5151
/// When a signal arrives elsewhere indicating that the socket is readable,
52-
/// `[Waker::wake]` is called and the socket future's task is awoken.
52+
/// [`Waker::wake`] is called and the socket future's task is awoken.
5353
/// Once a task has been woken up, it should attempt to `poll` the future
5454
/// again, which may or may not produce a final value.
5555
///
56-
/// Note that on multiple calls to `poll`, only the most recent
57-
/// [`Waker`] passed to `poll` should be scheduled to receive a
58-
/// wakeup.
56+
/// Note that on multiple calls to `poll`, only the [`Waker`] from the
57+
/// [`Context`] passed to the most recent call should be scheduled to
58+
/// receive a wakeup.
5959
///
6060
/// # Runtime characteristics
6161
///
@@ -77,15 +77,15 @@ pub trait Future {
7777
/// thread pool (or something similar) to ensure that `poll` can return
7878
/// quickly.
7979
///
80-
/// An implementation of `poll` may also never cause memory unsafety.
81-
///
8280
/// # Panics
8381
///
84-
/// Once a future has completed (returned `Ready` from `poll`),
85-
/// then any future calls to `poll` may panic, block forever, or otherwise
86-
/// cause any kind of bad behavior except causing memory unsafety.
87-
/// The `Future` trait itself provides no guarantees about the behavior
88-
/// of `poll` after a future has completed.
82+
/// Once a future has completed (returned `Ready` from `poll`), calling its
83+
/// `poll` method again may panic, block forever, or cause other kinds of
84+
/// problems; the `Future` trait places no requirements on the effects of
85+
/// such a call. However, as the `poll` method is not marked `unsafe`,
86+
/// Rust's usual rules apply: calls must never cause undefined behavior
87+
/// (memory corruption, incorrect use of `unsafe` functions, or the like),
88+
/// regardless of the future's state.
8989
///
9090
/// [`Poll::Pending`]: ../task/enum.Poll.html#variant.Pending
9191
/// [`Poll::Ready(val)`]: ../task/enum.Poll.html#variant.Ready

0 commit comments

Comments
 (0)