相关疑难解决方法(0)

函数签名上缺少生命周期说明符[E0106]

我很困惑这个简单代码(Playground)的错误:

fn main() {
    let a = fn1("test123");
}

fn fn1(a1: &str) -> &str {
    let a = fn2();
    a
}

fn fn2() -> &str {
    "12345abc"
}
Run Code Online (Sandbox Code Playgroud)

这些是:

error[E0106]: missing lifetime specifier
  --> <anon>:10:13
   |
10 | fn fn2() -> &str {
   |             ^ expected lifetime parameter
   |
   = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
   = help: consider giving it a 'static lifetime …
Run Code Online (Sandbox Code Playgroud)

rust

8
推荐指数
1
解决办法
6614
查看次数

标签 统计

rust ×1