How does the compiler determine if a future is `Send`?

Hello every one! I'm currently learning async programming in Rust but get confused on the Send bound of futures.

If I understand the async syntax correctly, the async function code such as

async fn basic() -> io::Result<()> {

transformed to

fn basic() -> impl std::future::Future<Output=io::Result<()>> {
    async move {

My question is how the compiler infer if the returned future(i.e., the returned impl future) has Send bound? Can the Send bound be automatically inferred with the impl type?

Yes. The very same way any other trait bound is inferred.

Thank you! Could you provide me some materials or doc on the automatic bound inference of impl type? Do all impl types and bounds work the same way as futures?

The Rust compiler developer docs has a section on it.

1 Like

Wow thanks! So the automatic inference only works for auto-traits, right? Since the doc mentions

Send is not listed amongst the bounds of the impl trait, but because of auto-trait leakage, we are able to infer that it holds.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.