Description
What it does
If future returns Pending, it should use the provided waker to notify executor that it can be polled again.
If the waker is not stored, the future will be unable to notify it and therefore it will be never polled again. Such a future is probably incorrect.
What is verified
(Probably imprecise, so just a proposal.)
For each MIR block B0
whose terminator is return
clippy should check that there is least one maybe-predecessor statement (i.e. defined in a block B1
, and B0
is reachable from B1
in CFG) which somehow uses cx
.
Categories (optional)
- Kind: correctness
Drawbacks
False-positive here is a future that sometimes diverges and sometimes terminates (because if a future always diverges that programmer should use futures_util::future::pending()
instead). I think such features are rare but don't have any estimations or experiments.
Example
impl Future for MyFut {
type Output = ...;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match self.state() {
// ...
State::Foo => {
// oops, we've forgotten to store waker, future will be never polled again
Poll::Pending
}
}
}
}