-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Closed
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.Category: This is a bug.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.P-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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.
95th, 0x8f701 and y8y
Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.Category: This is a bug.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.P-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Status
Done