Repository navigation
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
Description
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
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
Activity
compiler-errors commentedon Jun 19, 2022
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
FnOnceimplementation not being general enough.estebank commentedon Oct 12, 2026
Current output:
We should point at
fixas the "expected closure" (the message clearly doesn't account for the error happening on non-closures either).