Skip to content

Nonsensical diagnostic when returning closure #89620

Closed
@danielkeller

Description

@danielkeller

Given the following code:

fn bar<Input>() -> impl Fn(Input) {
    |i| todo!()
}
    
fn foo() -> impl Fn(&str) {
    bar()
}

The current output is:

error[E0308]: mismatched types
 --> src/lib.rs:5:13
  |
1 | fn bar<Input>() -> impl Fn(Input) {
  |                    --------------
  |                    |
  |                    the expected opaque type
  |                    the found opaque type
...
5 | fn foo() -> impl Fn(&str) {
  |             ^^^^^^^^^^^^^ one type is more general than the other
  |
  = note: expected associated type `<impl Fn<(&str,)> as FnOnce<(&str,)>>::Output`
             found associated type `<impl Fn<(&str,)> as FnOnce<(&str,)>>::Output`

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

It seems like a bug that the "expected" and "found" types are the same.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.T-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