Open
Description
Compiling this program:
use futures::stream::StreamExt;
use futures::{FutureExt, SinkExt};
fn main() {
tokio::runtime::Runtime::new().unwrap().spawn(do_stuff());
}
async fn do_stuff() {
let (mut tx, rx) = futures::channel::mpsc::channel::<u32>(10);
tokio::spawn(async move {
tx.send(1).await.unwrap();
});
rx.filter_map(|x| {
println!("received a {}", x);
std::future::ready(Some(Ok(x))).boxed()
})
.forward(futures::sink::drain())
.await;
}
results in the confusing compiler error:
error[E0308]: mismatched types
--> src/main.rs:5:45
|
5 | tokio::runtime::Runtime::new().unwrap().spawn(do_stuff());
| ^^^^^ one type is more general than the other
|
= note: expected struct `Pin<Box<dyn futures::Future<Output = Option<Result<u32, Infallible>>> + std::marker::Send>>`
found struct `Pin<Box<dyn futures::Future<Output = Option<Result<u32, Infallible>>> + std::marker::Send>>`
I expected this program to compile and print received a 1
to stdout.
Doing any of the following will make the program pass compilation (maybe due to how type inference changes?):
- changing
.spawn()
to.block_on()
in the main function - removing the
.boxed()
call
Meta
rustc --version --verbose
:
rustc 1.57.0-nightly (e1e9319d9 2021-10-14)
binary: rustc
commit-hash: e1e9319d93aea755c444c8f8ff863b0936d7a4b6
commit-date: 2021-10-14
host: x86_64-pc-windows-msvc
release: 1.57.0-nightly
LLVM version: 13.0.0
This error is also reproducible on the latest stable and latest nightly on the playground.
Playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=cd86e8ecc0289ad192a465214eae3f76