Skip to content

E0308 expected and found are identical #97010

Open
@jendrikw

Description

@jendrikw

Given the following code: play

fn rec_clone<'a>(v: &'a str, rec: &dyn Fn(&'a str) -> String) -> String {
    todo!()
}

pub fn clone() -> impl Fn(&str) -> String {
    fix::<&str, String>(rec_clone)
}

// https://stackoverflow.com/a/42182841
fn fix<A, B>(func: fn(A, &dyn Fn(A) -> B) -> B) -> impl Fn(A) -> B {
    move |val: A| func(val, &fix(func))
}

The current output is:

error[E0308]: mismatched types
  --> src/lib.rs:5:19
   |
5  | pub fn clone() -> impl Fn(&str) -> String {
   |                   ^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
...
10 | fn fix<A, B>(func: fn(A, &dyn Fn(A) -> B) -> B) -> impl Fn(A) -> B {
   |                                                    ---------------
   |                                                    |
   |                                                    the expected opaque type
   |                                                    the found opaque type
   |
   = note: expected associated type `<impl Fn(&str)-> String as FnOnce<(&str,)>>::Output`
              found associated type `<impl Fn(&str)-> String as FnOnce<(&str,)>>::Output`

It's irritating that expected and found are the same. Also "one type is more general than the other" could give an explanation why one is more general (like, what parameter). And, I don't know how FnOnce::Output is relevant.

One more thing: When you delete the return type from the signature of clone, it says expected unit type `()` found opaque type `impl Fn(&Fix<FC>)-> Fix<FC>` , which when implemented, doesn't work.

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