With nightly rust:
struct Foo<T, F: Fn(&T, &T) -> T> {
value: T,
func: F
}
fn main() {
let lambda = |&x, &y| x + y;
let foo = Foo {
value: 5 as i32,
func: lambda
};
}
Error message:
Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
--> src/main.rs:8:15
|
8 | let foo = Foo {
| ^^^ one type is more general than the other
|
= note: expected type `std::ops::FnOnce<(&i32, &i32)>`
found type `std::ops::FnOnce<(&i32, &i32)>`
Note that the expected type and found type are character for character identical. Why is the error message saying that one type is more general than the other, while also saying that they are the same type?