Checking for Send across awaits misses clear case?


In this playground, I've reproduced the issue in its entirety, but let me summarize it here.

Basically, Rust sensibly allows us to ensure that all variables in the local context are Send when encountering an .await --- after all, we may be scheduled back onto a different thread! However, the calculation misses a fairly obvious circumstance: what if we manually drop all the non-Send objects first? For example, where ns is a non-Send object:

async fn driver() {
    let ns = factory();
    // invoke something on it that we want to use later that returns a Copy so we can drop ns
    let v : usize = ns.dummy();
    // compiler complains that ns may be used across this await, but it's been dropped!

If this is wrapped in braces to make the dropping unambiguous, it works as expected. However, that makes passing data around a little more awkward.

Are there any plans to deal with this edge-case? Is this a known issue?

The behavior is documented in the async book, and there's also a tracking issue. Looks like a fix is in progress.


Aha, yep, there we go. Thanks!

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.