Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A vague error, and I don't know what the problem is #1835

Closed
driftluo opened this issue Nov 27, 2019 · 7 comments
Closed

A vague error, and I don't know what the problem is #1835

driftluo opened this issue Nov 27, 2019 · 7 comments

Comments

@driftluo
Copy link
Contributor

driftluo commented Nov 27, 2019

version: tokio 0.2.1

I even don’t know where this question should be mentioned, and I feel vague that this should be a rustc problem. If so, please tell me, I will write the problem over rustc again

Example:

use futures::{
    channel::mpsc::channel,
    stream::{iter, pending},
    SinkExt, StreamExt,
};
use std::future::Future;
use std::pin::Pin;

pub(crate) type BoxedFutureTask = Pin<Box<dyn Future<Output = ()> + 'static + Send>>;

fn main() {
    let mut rt = tokio::runtime::Runtime::new().unwrap();
    let (sender, mut receiver) = channel(128);
    rt.block_on(async move {
        tokio::spawn(async move {
            let mut tasks = iter(
                (1..100)
                    .map(|_| {
                        Box::pin(async {
                            let mut stream = pending::<()>();
                            loop {
                                stream.next().await;
                            }
                        }) as BoxedFutureTask
                    })
                    .collect::<Vec<_>>(),
            )
            .map(Ok);
            let _ = sender.send_all(&mut tasks).await;
        });
        loop {
            if receiver.next().await.is_none() {
                break
            }
        }
    })
}

will output:

error[E0308]: mismatched types
  --> src/main.rs:12:9
   |
12 |         tokio::spawn(async move {
   |         ^^^^^^^^^^^^ one type is more general than the other
   |
   = note: expected type `std::ops::FnOnce<(std::pin::Pin<std::boxed::Box<dyn core::future::future::Future<Output = ()> + std::marker::Send>>,)>`
              found type `std::ops::FnOnce<(std::pin::Pin<std::boxed::Box<dyn core::future::future::Future<Output = ()> + std::marker::Send>>,)>`

error: aborting due to previous error

but change BoxedFutureTask to () like follow, it works well

fn main () {
    let mut rt = tokio::runtime::Runtime::new().unwrap();
    let (mut sender, mut receiver) = channel(128);
    rt.block_on(async move {
        tokio::spawn(async move {
            let mut tasks = iter(
            (1..100)
                .map(|_| {
                    ()
                })
                .collect::<Vec<_>>(),
            ).map(Ok);
            let _ = sender.send_all(&mut tasks).await;
        });
        loop {
            if receiver.next().await.is_none() {
                break
            }
        }
    })
}

I am very puzzled about this, Vec<Pin<Box<dyn Future <Output = () >> + 'static + Send >> is a correct value, and the error here makes me overwhelmed.

@jebrosen
Copy link
Contributor

Possibly related: rust-lang/rust#64650, rust-lang/rust#60658.

@carllerche
Copy link
Member

Looks like a compiler bug

@LucioFranco
Copy link
Member

LucioFranco commented Nov 27, 2019

is it the order of pub(crate) type BoxedFutureTask = Pin<Box<dyn Future<Output = ()> + 'static + Send>>;

Maybe it should be pub(crate) type BoxedFutureTask = Pin<Box<dyn Future<Output = ()> + Send + 'static>>;? I think the order in a trait object matter.

@ernestas-poskus
Copy link

Same here

48 |         let _ = tokio::spawn(watcher::watch_health(
   |                 ^^^^^^^^^^^^ one type is more general than the other
   |
   = note: expected type `std::ops::FnOnce<(&&str,)>`
              found type `std::ops::FnOnce<(&&str,)>`

@LucioFranco
Copy link
Member

@ernestas-poskus seems like a compiler error, I would report this upstream.

@Aaron1011
Copy link
Contributor

This seems to be another case of rust-lang/rust#64552. The compiler is "forgetting" that certain regions are 'static, and that certain regions are actually equal to each other. This leads to an incomprehensible error being reported - the two types really are equal, but we've erased the information that would allow us to determine this.

@Darksonn
Copy link
Contributor

Closing as this is not our bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants