Ploppz
February 28, 2020, 9:11am
#1
I cannot use .boxed() because it triggers errors about "one type is more general than the other".
So I use Box::pin()
instead which works fine. However, the reason I use box at all here is that I need to reduce the type size of the future because I hit the compiler limit, so I need to cast it to Box<Pin<dyn ..>> I suppose? Will that help?
But it seems I cannot escape my fate which is "one type is more general than the other": https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=c0b057e9f9f6b9be9e064c3d68f57676 (edit: wrong link)
I have been wrestling with these errors almost a whole week and I'm desperate for a solution. Please help
kornel
February 28, 2020, 3:52pm
#2
I must admit, the error message is utterly confusing. I think it's worth filing a bug about it.
Removing this line makes it compile:
.then(move |x| async move {x})
Ploppz
February 28, 2020, 4:18pm
#3
I know that removing that line solves the problem, and I forgot to say: this is a very reduced test case deriving from a larger application where I actually need the then
call, but where I do something more, namely
.then(move |x| async move {
delay_for(Duration::from_secs(some_time)).await;
x
})
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
system
closed
May 28, 2020, 4:21pm
#5
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.