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

Passing mutating async function gives unhelpful duplicate type error #112855

Open
sophiajt opened this issue Jun 20, 2023 · 0 comments
Open

Passing mutating async function gives unhelpful duplicate type error #112855

sophiajt opened this issue Jun 20, 2023 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@sophiajt
Copy link
Contributor

sophiajt commented Jun 20, 2023

Code

async fn mutate(t: &mut i64) {
    *t += 1000;
}

fn use_async_fn<A, U>(_fun: A)
where
    A: Fn(&mut i64) -> U,
    U: futures::Future<Output = ()>,
{
}

fn main() {
    use_async_fn(mutate);
}

Current output

error[E0308]: mismatched types
  --> src/main.rs:13:5
   |
13 |     use_async_fn(mutate);
   |     ^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
   |
   = note: expected trait `for<'a> <for<'a> fn(&'a mut i64) -> impl futures::Future<Output = ()> {mutate} as FnOnce<(&'a mut i64,)>>`
              found trait `for<'a> <for<'a> fn(&'a mut i64) -> impl futures::Future<Output = ()> {mutate} as FnOnce<(&'a mut i64,)>>`
note: the lifetime requirement is introduced here
  --> src/main.rs:7:24
   |
7  |     A: Fn(&mut i64) -> U,
   |                        ^

Desired output

Rather than show the same type twice, rustc should explain what the actual mismatch between the two types is.

If you want to get fancy, it could explain how to pass async mutating functions properly :D

Rationale and extra context

If we find that we'll show the same type twice to the user after stringifying it, we may want to give additional context to help the user better understand what is being shown.

Other cases

No response

Anything else?

No response

@sophiajt sophiajt added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 20, 2023
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant