Unhelpful error when providing a borrowed closure to a function expecting a closure taking borrowed arguments
bb9a916
Opened by Josh Matthews at
fn foo<F>(_compare: F) where F: Fn(&u8) {
}
fn main() {
foo(&|_a| {});
}
yields this unhelpful series of errors:
error[E0271]: type mismatch resolving `for<'r> <&[closure@<anon>:5:10: 5:17] as std::ops::FnOnce<(&'r u8,)>>::Output == ()`
--> <anon>:5:5
|
5 | foo(&|_a| {});
| ^^^ expected bound lifetime parameter , found concrete lifetime
|
= note: concrete lifetime that was found is lifetime '_#5r
= note: required by `foo`
error[E0281]: type mismatch: the type `[closure@<anon>:5:10: 5:17]` implements the trait `std::ops::Fn<(_,)>`, but the trait `for<'r> std::ops::Fn<(&'r u8,)>` is required (expected concrete lifetime, found bound lifetime parameter )
--> <anon>:5:5
|
5 | foo(&|_a| {});
| ^^^
|
= note: required because of the requirements on the impl of `for<'r> std::ops::Fn<(&'r u8,)>` for `&[closure@<anon>:5:10: 5:17]`
= note: required by `foo`
error: aborting due to 2 previous errors
Current output:
error[E0271]: type mismatch resolving `for<'r> <&[closure@file4.rs:5:10: 5:17] as std::ops::FnOnce<(&'r u8,)>>::Output == ()` --> file4.rs:5:5 | 1 | fn foo<F>(_compare: F) where F: Fn(&u8) { | --- ------- required by this bound in `foo` ... 5 | foo(&|_a| {}); | ^^^ expected bound lifetime parameter, found concrete lifetimeEsteban Kuber at 2020-02-05 00:44:49