Given the following code:
struct X<'a>(&'a ());
struct S<'a>(&'a dyn Fn(&X) -> &X);
fn main() {
let x = S(&|x| {
println!("hi");
x
});
x.0(&X(&()));
}
we currently give the following output
error[E0106]: missing lifetime specifier
--> src/main.rs:2:32
|
2 | struct S<'a>(&'a dyn Fn(&X) -> &X);
| -- ^ expected named lifetime parameter
|
= help: this function's return type contains a borrowed value, but the signature does not say which one of argument 1's 2 lifetimes it is borrowed from
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the bound lifetime-generic with a new `'a` lifetime
|
2 | struct S<'a>(&'a dyn for<'a> Fn(&'a X) -> &'a X);
| ^^^^^^^ ^^^^^ ^^^
help: consider introducing a named lifetime parameter
|
2 | struct S<'a, 'a>(&'a dyn Fn(&'a X) -> &'a X);
| ^^^ ^^^^^ ^^^
error[E0106]: missing lifetime specifier
--> src/main.rs:2:33
|
2 | struct S<'a>(&'a dyn Fn(&X) -> &X);
| -- ^ expected named lifetime parameter
|
= help: this function's return type contains a borrowed value, but the signature does not say which one of argument 1's 2 lifetimes it is borrowed from
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the bound lifetime-generic with a new `'a` lifetime
|
2 | struct S<'a>(&'a dyn for<'a> Fn(&'a X) -> &X<'a>);
| ^^^^^^^ ^^^^^ ^^^^^
help: consider introducing a named lifetime parameter
|
2 | struct S<'a, 'a>(&'a dyn Fn(&'a X) -> &X<'a>);
| ^^^ ^^^^^ ^^^^^
Beyond the verbosity, one of the suggestions offers struct S<'a, 'a>, which is not ideal.
Given the following code:
we currently give the following output
Beyond the verbosity, one of the suggestions offers
struct S<'a, 'a>, which is not ideal.