Open
Description
The following code:
struct MyType;
fn parse_header<T, F: FnOnce(&MyType) -> T>(parse: F) -> T {
panic!()
}
fn make_it(val: &MyType) -> &MyType { panic!() }
pub fn from_url<'a>() -> &'a MyType {
parse_header(make_it)
}
fn main() {}
gives this error:
error[E0271]: type mismatch resolving `for<'r> <for<'s> fn(&'s MyType) -> &'s MyType {make_it} as std::ops::FnOnce<(&'r MyType,)>>::Output == _`
--> src/main.rs:10:5
|
3 | fn parse_header<T, F: FnOnce(&MyType) -> T>(parse: F) -> T {
| - required by this bound in `parse_header`
...
10 | parse_header(make_it)
| ^^^^^^^^^^^^ expected bound lifetime parameter, found concrete lifetime
There are several issues with this error:
- The 'type mismatch' message contains several pieces of 'internal' rust syntax (multiple consecutive
for<>
binders, the weird{make_it}
syntax for function pointers, and an inference variable). - We call the return type
T
a 'bound', even though it's clearly not a bound. - We give an confusing 'expected bound lifetime parameter, found concrete lifetime' message, which doesn't really explain what's going on
- We don't point at
make_it
, even though it's part of the issue.
This was minimized from code posted by @rvolosatovs.