Skip to content

Confusing HRTB mismatching diagnostic message #104484

Closed
@ethe

Description

@ethe

Given the following code:

use std::future::Future;

async fn foo<F, R>(f: F) -> bool
where
    F: Fn(&u8) -> R,
    R: Future<Output = bool>,
{
    todo!()
}

async fn bar() {
    foo(fut).await;
}

async fn fut(param: &u8) -> bool {
    todo!()
}

The current output is:

Standard Error
   Compiling playground v0.0.1 (/playground)
error[[E0308]](https://doc.rust-lang.org/stable/error-index.html#E0308): mismatched types
  --> src/lib.rs:12:5
   |
12 |     foo(fut).await;
   |     ^^^^^^^^ one type is more general than the other
   |
   = note: expected trait `for<'r> <for<'r> fn(&'r u8) -> impl for<'r> Future<Output = bool> {fut} as FnOnce<(&'r u8,)>>`
              found trait `for<'r> <for<'r> fn(&'r u8) -> impl for<'r> Future<Output = bool> {fut} as FnOnce<(&'r u8,)>>`
note: the lifetime requirement is introduced here
  --> src/lib.rs:5:19
   |
5  |     F: Fn(&u8) -> R,
   |                   ^

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` due to previous error

the note be provided by rustc makes me confused:

for<'r> <for<'r> fn(&'r u8) -> impl for<'r> Future<Output = bool> {fut} as FnOnce<(&'r u8,)>>
!=
for<'r> <for<'r> fn(&'r u8) -> impl for<'r> Future<Output = bool> {fut} as FnOnce<(&'r u8,)>>

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions