You are running into the Send Approximation being too conservative. The compiler does not like to see a let binding for a non-Send type and an .await statement in the same scope. It is not (yet) smart enough to know that the non-Send type is already consumed by the time of the .await.
You've already discovered the workaround in your three(). To make it more concise
async fn four() {
let content = do_stuff().err().map(|err| err.to_string());
if let Some(content) = content {
let _ = do_stuff_2(content).await;
}
}
You are running into the Send Approximation being too conservative. The compiler does not like to see a let binding for a non-Send type and an
.awaitstatement in the same scope. It is not (yet) smart enough to know that the non-Send type is already consumed by the time of the.await.You've already discovered the workaround in your
three(). To make it more concise