Open
Description
Here's an example which I think should compile, but which doesn't (cargo 1.39.0-nightly 3f700ec43 2019-08-19):
#![feature(async_await)]
fn require_send<T: Send>(_: T) {}
struct NonSendStruct { _ptr: *mut () }
async fn my_future() {
let nonsend = NonSendStruct { _ptr: &mut () };
async {}.await;
}
fn main() {
require_send(my_future()); // error: `*mut ()` cannot be sent between threads safely
}
The error is "*mut ()
cannot be sent between threads safely", which is to say my_future()
is !Send
. I'm surprised by that, because the nonsend
variable is never used after the .await
point, and it's not Drop
. Some other notes:
- Adding a
drop(nonsend)
call after thelet nonsend = ...
line doesn't help. - This does compile if swap the two lines in
my_future
. That is, ifnonsend
is created after the.await
point, the future is stillSend
.
Are there any future plans to have the rustc look more closely at which locals do or do not need to be stored across an .await
?