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

Confusing mismatched types error with the same expected/found types when universes are involved #124471

Open
WaffleLapkin opened this issue Apr 28, 2024 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: lifetime related D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@WaffleLapkin
Copy link
Member

Code

fn main() {
    consume_fn(identity);
}

fn identity(x: &u32) -> &u32 { x }

fn consume_fn<F>(_: impl FnOnce(&u32) -> F) {}

Current output

error[E0308]: mismatched types
 --> ./t.rs:4:5
  |
4 |     consume_fn(identity);
  |     ^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
  |
  = note: expected reference `&_`
             found reference `&_`
note: the lifetime requirement is introduced here
 --> ./t.rs:9:42
  |
9 | fn consume_fn<F>(_: impl FnOnce(&u32) -> F) {}
  |                                          ^

Desired output

error[E0308]: mismatched types
 --> ./t.rs:4:5
  |
4 |     consume_fn(identity);
  |     ^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
  |
  = note: expected reference `&'1 _`
             found reference `for<'2> &'2 _`
note: the lifetime requirement is introduced here
 --> ./t.rs:9:42
  |
9 | fn consume_fn<F>(_: impl FnOnce(&u32) -> F) {}
  |                                          ^

Rationale and extra context

Emitting expected/found with the same thing is not very helpful. Ideally we would also mention why the types can't be actually equal here (F being a concrete type and not being able to mention the lifetime in FnOnce), but I'm not sure how to best fit it in an error message.

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?

No response

@WaffleLapkin WaffleLapkin added A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: lifetime related T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-types Relevant to the types team, which will review and decide on the PR/issue. labels Apr 28, 2024
@lqd lqd changed the title Consfusing mismatched types error with the same expected/found types when universes are involved Confusing mismatched types error with the same expected/found types when universes are involved Apr 28, 2024
@fmease
Copy link
Member

fmease commented Apr 30, 2024

cc #112985.

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: lifetime related D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants