我错在哪里😥?。
fn main_FnOnce() {
fn fn_immut<F>(f: F) where F: FnOnce() -> String {
println!("run {}", f());
}
fn fn_immutb<F>(f: F) where F: for<'a> Fn() -> &'a String {
println!("run {}", f());
}
let a = "Fn".to_string();
let b = &"Fn".to_string();
let f = || a;
let fb = || b;
fn_immut(f);
fn_immutb(fb);
}
error[E0261]: use of undeclared lifetime name `'a`
--> src\main.rs:56:21
|
56 | F: Fn() -> &'a String,
| ^^ undeclared lifetime
|
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider introducing lifetime `'a` here
|
54 | fn fn_immutb<'a, F>(f: F)
| ^^^
help: consider making the bound lifetime-generic with a new `'a` lifetime
|
56 | F: for<'a> Fn() -> &'a String,
| ^^^^^^^
error: aborting due to previous error; 1 warning emitted
1
共 8 条评论, 1 页
评论区
写评论对不起喔问完后上来 字体主题: Cascadia Code
--
👇
leslieDD: 可以贴一下你用的主题么
可以贴一下你用的主题么
请问你用的是什么字体啊,可以贴一下么~~~
感谢,已解决。
--
👇
ZIP97: 没有给
'a
添加泛型声明没有给
'a
添加泛型声明终端里编译打印的信息发上来。
救救出学者。
--
👇
Mike Tang: 编译错误信息来一个
编译错误信息来一个