Closed
Description
Especially the fact that the lines are broken up seems like a bug.
use core::future::Future;
use futures::future::{BoxFuture, FutureExt};
async fn baz<T>(_c: impl FnMut() -> T) where T: Future<Output=()> {
}
fn foo(tx: std::sync::mpsc::Sender<i32>) -> BoxFuture<'static, ()>{
async move {
baz(|| async{
foo(tx.clone());
}).await;
}.boxed()
}
fn bar(_s: impl Future + Send) {
}
fn main() {
let (tx, _rx) = std::sync::mpsc::channel();
bar(foo(tx));
}
Errors:
Compiling playground v0.0.1 (/playground)
error: future cannot be sent between threads safely
--> src/main.rs:12:7
|
12 | }.boxed()
| ^^^^^ future returned by `foo` is not `Send`
|
= help: the trait `std::marker::Sync` is not implemented for `std::sync::mpsc::Sender<i32>`
note: future is not `Send` as this value is used across an await
--> src/main.rs:9:9
|
9 | baz(|| async{
| __________^___-
| | _________|
| ||
10 | || foo(tx.clone());
11 | || }).await;
| || - ^- `|| async{
foo(tx.clone());
}` is later dropped here
| ||_________|______|
| |__________| await occurs here, with `|| async{
foo(tx.clone());
}` maybe used later
| has type `[closure@src/main.rs:9:13: 11:10 tx:&std::sync::mpsc::Sender<i32>]`
error: aborting due to previous error
error: could not compile `playground`.
To learn more, run the command again with --verbose.
@rustbot modify labels: A-diagnostics, C-bug, D-papercut, T-compiler
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.Diagnostics: An error or lint that needs small tweaks.Medium priorityRelevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Status
Done