【问题标题】:How to resolve "indicate anonymous lifetime <'_>" error?如何解决“指示匿名生命周期<'_>”错误?
【发布时间】:2021-02-12 12:13:59
【问题描述】:
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: `<'_>`

我应该在哪里指定这个匿名生命周期?我也不是很了解它的必要性。如果参数是借用的,为什么还需要一个生命周期?

【问题讨论】:

    标签: rust reference lifetime borrow-checker borrowing


    【解决方案1】:

    clap 中的 ArgMatches&lt;'a&gt; 结构在生命周期内是通用的。您尚未在函数中写出 args 的完整类型,因为您省略了 ArgMatches 结构的生命周期参数,这就是编译器抱怨类型参数“隐藏”并建议您提供args 的完整类型,通过编写 ArgMatches&lt;'_&gt; 使您的代码更加明确和清晰。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-10
      • 1970-01-01
      • 2022-11-06
      • 1970-01-01
      • 1970-01-01
      • 2022-07-02
      • 2022-11-02
      • 2017-05-03
      相关资源
      最近更新 更多