Can a future used only by `async fn` assume it won't be polled again after becoming ready?
โ Rust ๐ 2026-03-30 ๐ค surdeus ๐๏ธ 8Are there any guarantees about what an async fn will do if its future is polled again after it completes? In particular, given the following situationโฆ
pub async fn foo(foo: Foo) {
// We await the Foo, then never use it again.
foo.await;
}
struct Foo;
impl Future for Foo {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<()> {
todo!();
}
}
โฆI'm wondering whether Foo::poll can assume that it will never be called again after returning Poll::Ready. I know that assumption is not sound in general, but I can imagine that in the case where you know all callers are .await expressions in async fns that own the future it might be okay, assuming that the async fns already have their own "panic if polled again after completion" logic internally.
5 posts - 5 participants
๐ท๏ธ Rust_feed