How to resolve "indicate anonymous lifetime <'_>" error?

Viewed 3431
warning: hidden lifetime parameters in types are deprecated
  --> asd/src/app/qwe.rs:88:45
   |
88 |     fn add_meta_from_args(&mut self, args: &ArgMatches) -> AppRun {
   |                                             ^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>`

Where should I specify this anonymous lifetime? I don't really understand the need for it either. If the parameter is borrowed, why does it need a lifetime as well?

1 Answers

The ArgMatches<'a> struct within clap is generic over lifetimes. You haven't written out the full type of args in your function because you have omitted the lifetime parameter of the ArgMatches struct, which is why the compiler is complaining the type parameter is "hidden" and is suggesting you provide the full type for args by writing ArgMatches<'_> to make your code more explicit and clear.

Related