Closed
Description
The following code (playground):
fn main() {
let send_fut = async {
let non_send_fut = make_non_send_future();
let _ = non_send_fut.await;
ready(0).await;
};
require_send(send_fut);
}
Gives an error message stating that non_send_fut
can live until the end of the scope, and that's why send_fut
is not Send
:
error: future cannot be sent between threads safely
--> src/main.rs:18:5
|
6 | fn require_send(_: impl Send) {}
| ------------ ---- required by this bound in `require_send`
...
18 | require_send(send_fut);
| ^^^^^^^^^^^^ future returned by `main` is not `Send`
|
= help: the trait `std::marker::Sync` is not implemented for `std::cell::RefCell<i32>`
note: future is not `Send` as this value is used across an await
--> src/main.rs:16:9
|
14 | let non_send_fut = make_non_send_future();
| ------------ has type `impl core::future::future::Future`
15 | let _ = non_send_fut.await;
16 | ready(0).await;
| ^^^^^^^^^^^^^^ await occurs here, with `non_send_fut` maybe used later
17 | };
| - `non_send_fut` is later dropped here
but it doesn't; it's consumed by value when it gets awaited. The problem is we're awaiting a non-Send
future inside of send_fut
, which has to be Send
.
Also, the text
future returned by `main` is not `Send`
is wrong; main
doesn't return anything.
Thanks to @kellerb for the reproducer and @JakeEhrlich for originally reporting this.
Metadata
Metadata
Assignees
Labels
Area: Async & AwaitArea: Messages for errors, warnings, and lintsAsync-await issues that have been triaged during a working group meeting.Category: This is a bug.Category: An issue proposing an enhancement or a PR with one.Diagnostics: A diagnostic that is giving misleading or incorrect information.High priorityRelevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Status
Done