There is an issue already:
opened 06:26AM - 21 Sep 19 UTC
C-enhancement
A-diagnostics
T-compiler
A-async-await
AsyncAwait-Triaged
D-confusing
D-newcomer-roadblock
The following code does not compile:
```rust
// Crate versions:
// futures-… preview v0.3.0-alpha.18
// runtime v0.3.0-alpha.7
use futures::{prelude::*, stream::FuturesUnordered};
#[runtime::main]
async fn main() {
let entries: Vec<_> = vec![()]
.into_iter()
.map(|x| async { vec![()].into_iter().map(|_| x) })
.collect::<FuturesUnordered<_>>()
.map(stream::iter)
.flatten()
.collect()
.await;
}
```
It produces this error message:
```
error[E0308]: mismatched types
--> src\main.rs:3:1
|
3 | #[runtime::main]
| ^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected type `std::ops::FnOnce<(std::iter::Map<std::vec::IntoIter<()>, [closure@src\main.rs:7:51: 7:56 x:&()]>,)>`
found type `std::ops::FnOnce<(std::iter::Map<std::vec::IntoIter<()>, [closure@src\main.rs:7:51: 7:56 x:&()]>,)>`
```
In this case, the code can be made to compile by adding `move` in two places on this line:
```rust
// ...
.map(|x| async move { vec![()].into_iter().map(move |_| x) })
// ...
```
Some possibly related issues: #57362, #60658
**rustc version:** `1.39.0-nightly (97e58c0d3 2019-09-20)`
Some threads from the user forum:
It seems it's sometimes related to lifetimes of the closure. Sometimes you can work around that with a dedicated function on which you can set for<'a>
, although nobody has posted an example of that I think.
In the last thread it seems to be related to Send
.
I have an async fn that returns a value I pass to Tokio's tokio::spawn() that compiled, but had a bug. Trying to fix the bug by modifying a statement in the function caused the program to not compile anymore. I'm using the alpha version of Tokio (the one that supports async/.await). The error is:
error[E0308]: mismatched types
--> src/wormhole.rs:55:9
|
55 | tokio::spawn(session);
| ^^^^^^^^^^^^ one type is more general than the other
|
= note: expected type tokio_io::io:…
Writing agent_factory as _, I get the same error as before.
What I did was: let exp = CoverageExperiment::new(agent_factory as _, domain_factory, episode_length);
One thing I find strange is that I have had no such problem with domain_factory, which is Box<dyn Fn() -> D>. (created like this: let domain_factory = Box::new(Env::default);)
I will write a minimal test case when I have time.
It compiled when I change some code.
use futures;
use futures::{StreamExt};
use async_std::prelude::*;
use async_std::task;
use std::time::Duration;
use async_std::sync::RwLock;
use futures::channel::mpsc::{UnboundedSender, UnboundedReceiver, unbounded};
async fn test() {
let state = &RwLock::new(5i32);
let (query_tx, query_rx) = unbounded::<i32>();
let (tx, rx) = unbounded::<i32>();
let task_write = async {
for i in 1..5 {
query_tx.unbounded_send(i).unwr…
1 Like