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

"one type is more general than the other" error that appears to expect and find the same type #90656

Open
Arc-blroth opened this issue Nov 6, 2021 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions D-confusing Diagnostics: Confusing error or lint that should be reworked. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example

Comments

@Arc-blroth
Copy link

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

@Arc-blroth Arc-blroth added the C-bug Category: This is a bug. label Nov 6, 2021
@Munksgaard
Copy link
Contributor

I've encountered the same problem with this example:

fn symbol<'a>(s: &'a str) -> impl FnMut(&'a str) -> Result<&'a str, &'a str> {
    |_| unimplemented!()
}

static FOO: &(dyn FnMut(&str) -> Result<&str, &str> + Sync) = &symbol("*");

fn main() {}

Playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=384859be0ad2e507a0fb22f596e3b132

@ChrisDenton ChrisDenton added the needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. label Jul 16, 2023
@fmease fmease added A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions D-confusing Diagnostics: Confusing error or lint that should be reworked. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example and removed needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. C-bug Category: This is a bug. labels Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions D-confusing Diagnostics: Confusing error or lint that should be reworked. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
Projects
None yet
Development

No branches or pull requests

4 participants