Closed
Description
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.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Category: An issue proposing an enhancement or a PR with one.Diagnostics: A structured suggestion resulting in incorrect code.Diagnostics: An error or lint that needs small tweaks.Low priorityRelevant to the compiler team, which will review and decide on the PR/issue.