Closed
Description
E.g.
use std::cell::Cell;
fn f<'a>(f: fn(Cell<(&'a i32, &i32)>)) -> for<'l> fn(Cell<(&'l i32, &'l i32)>) {
f
}
chooses the lifetime name “'r
” for the fn-pointer type of the argument f
and prints
error[E0308]: mismatched types
--> src/lib.rs:4:5
|
3 | fn f<'a>(f: fn(Cell<(&'a i32, &i32)>)) -> for<'l> fn(Cell<(&'l i32, &'l i32)>) {
| ------------------------------------ expected `for<'l> fn(Cell<(&'l i32, &'l i32)>)` because of return type
4 | f
| ^ one type is more general than the other
|
= note: expected fn pointer `for<'l> fn(Cell<(&'l i32, &'l i32)>)`
found fn pointer `for<'r> fn(Cell<(&'a i32, &'r i32)>)`
For more information about this error, try `rustc --explain E0308`.
However, rewriting the code into
use std::cell::Cell;
type Ty = for<'r> fn(Cell<(&'r i32, &'r i32)>);
fn f<'r>(f: fn(Cell<(&'r i32, &i32)>)) -> Ty {
f
}
does not currently make the compiler reconsider the choice of “'r
” in the lifetime name, resulting in an unhelpful error message
error[E0308]: mismatched types
--> src/lib.rs:4:5
|
3 | fn f<'r>(f: fn(Cell<(&'r i32, &i32)>)) -> Ty {
| -- expected `for<'r> fn(Cell<(&'r i32, &'r i32)>)` because of return type
4 | f
| ^ one type is more general than the other
|
= note: expected fn pointer `for<'r> fn(Cell<(&'r i32, &'r i32)>)`
found fn pointer `for<'r> fn(Cell<(&'r i32, &'r i32)>)`