Can a future used only by `async fn` assume it won't be polled again after becoming ready?

โš“ Rust    ๐Ÿ“… 2026-03-30    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 8      

surdeus

Are 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

Read full topic

๐Ÿท๏ธ Rust_feed