You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error[E0308]: mismatched types
--> r.rs:5:5
|
5 | foo (cl);
| ^^^ one type is more general than the other
|
= note: expected type `FnOnce<(&i32,)>`
found type `FnOnce<(&i32,)>`
I fail to see the difference between the expected and actual type here. Also, which types is rustc even comparing? Where does the FnOnce come from?
Expected behavior: The code should compile, with the closure argument type being inferred as &i32. In fact, this is what happens as soon as I change the closure definition to
let cl = |c:&_| -> (){ c % 2;};
i.e. by adding a hint that c has to be a reference. But this is obvious from foo's signature, isn't it?
At least, there should be a less confusing error message.
Consider this code:
This produces the following error message:
I fail to see the difference between the expected and actual type here. Also, which types is rustc even comparing? Where does the
FnOnce
come from?Expected behavior: The code should compile, with the closure argument type being inferred as
&i32
. In fact, this is what happens as soon as I change the closure definition toi.e. by adding a hint that
c
has to be a reference. But this is obvious fromfoo
's signature, isn't it?At least, there should be a less confusing error message.
Meta
rustc --version --verbose
:rustc +nightly --version --verbose
:The text was updated successfully, but these errors were encountered: