Skip to content

Universe errors involving an opaque type results in hallucinations and unused bound vars #124472

Open
@WaffleLapkin

Description

Code (Rust ≥2018)

use std::future::Future;

fn main() {
    consume_async(async_fn);
}

async fn async_fn(_: &u32) {}

fn consume_async<F>(_: impl FnOnce(&u32) -> F) where F: Future<Output = ()> {}

Current output

error[E0308]: mismatched types
 --> ./t.rs:4:5
  |
4 |     consume_async(async_fn);
  |     ^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
  |
  = note: expected opaque type `impl for<'a> Future<Output = ()>`
             found opaque type `impl Future<Output = ()>`
  = help: consider `await`ing on both `Future`s
  = note: distinct uses of `impl Trait` result in different opaque types
note: the lifetime requirement is introduced here
 --> ./t.rs:9:45
  |
9 | fn consume_async<F>(_: impl FnOnce(&u32) -> F) where F: Future<Output = ()> {}
  |                                             ^

Desired output

error[E0308]: mismatched types
 --> ./t.rs:4:5
  |
4 |     consume_async(async_fn);
  |     ^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
  |
  = note: expected `_`
             found some type `for<'a> T<'a>` which implements `Future<Output = ()>`
note: the lifetime requirement is introduced here
 --> ./t.rs:9:45
  |
9 | fn consume_async<F>(_: impl FnOnce(&u32) -> F) where F: Future<Output = ()> {}
  |                                             ^

Rationale and extra context

It's very confusing to see a second opaque type and suggestions "to await both futures" (???, there is only one). Ideally we would properly note that the generic can't name the lifetime or something.

Other cases

No response

Rust Version

rustc 1.79.0-nightly (ef8b9dcf2 2024-04-24)
binary: rustc
commit-hash: ef8b9dcf23700f2e2265317611460d3a65c19eff
commit-date: 2024-04-24
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.4

Anything else?

#124471 has a simiular test case/issue but without the opaque types.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.D-confusingDiagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.fixed-by-async-closuresFixed by `#![feature(async_closure)]`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions