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

E0308 expected and found are identical #97010

Open
jendrikw opened this issue May 13, 2022 · 1 comment
Open

E0308 expected and found are identical #97010

jendrikw opened this issue May 13, 2022 · 1 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.

Comments

@jendrikw
Copy link
Contributor

jendrikw commented May 13, 2022

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.

@jendrikw jendrikw 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 May 13, 2022
@compiler-errors
Copy link
Member

This error message has improved with NLL on nightly, it still says this message above, but it also gives a more detailed message about the FnOnce implementation not being general enough.

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

2 participants