//`x` dropped here while still borrowed println!("r is {}",r); } 函数中的生命周期 fn longest<'a>(x:&'a str,y:&'a str) -> &'a str{ if(x.len()>y.len()) { x }else { y } } 结构体中的生命周期 #[derive(Debug)]structA<'a>{name:&'a str} 生命周期的省略 第一条规...
27 | foo = Foo {name: &s}; | ^^ borrowed value does not live long enough 28 | } | - `s` dropped here while still borrowed 29 | println!("{}", foo.name); | --- borrow later used here error: aborting due to previous error 结构体含有生命周期,可以理解为结构体包含引用,所以结构...
| ^^ borrowed value does not live long enough 7 | } | - `y` dropped here while still borrowed 8 | 9 | println!("the x value of {}", x); | - borrow later used here For more information about this error, try `rustc --explain E0597`. error: could not compile `playground` d...
l = longest(str1.as_str(), str2.as_str()); | ^^^ borrowed value does not live long enough 7 | } | - `str2` dropped here while still borrowed 分析这种情况比较简单,容易理解。logest返回值的生命周期和str1,str2一样, 其实就是str1和str2当中生命周期短的那个,就是str2。因为str2在 pr...
| - `b` dropped here while still borrowed 7 | println!("a:{}", a); | - borrow later used here 1. 2. 3. 4. 5. 6. 7. 8. 9. 意思就是说变量b的生命周期不够长。变量b已经被销毁了仍然对它进行了借用。 一个正确的例子:
chapter10)error[E0597]: `string2` does not live long enough --> src/main.rs:6:44 |6 | result = longest(string1.as_str(), string2.as_str()); | ^^^ borrowed value does not live long enough7 | } | - `string2` dropped here while still borrowed8 | println!("The ...
// ^^ borrowed value does not live long enough } // - `x` dropped here while still borrowed println!("r: {}", r); // - borrow later used here } } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. let r; 声明了一个变量,在内层语句块中变成对 x 变量的...
| - `some_string` dropped here while still borrowed 这算不算Rust的小陷阱还有待商榷,因为这不是&'static str到&'a str简单直接的强制转换, 而是for Fn() -> &'static T到for这种更复杂的情况。前者是值之间的强制转换,后者是类型之间的强制转换。
88 | } | - `original_contents` dropped here while still borrowed fn get_updated_contents<'old, 'new, 'out>( original_contents: String, descriptor_values: Vec<&str>, value_values: Vec<&str>, on_conflict: fn(&'old Vec<&'old str>, &'new Vec<&'new str>) -> &'out Vec<&'...
Compiling hello_cargo v0.1.0(/Users/zerun.dong/code/rusttest/hello_cargo)error[E0597]:`x`does not live long enough-->src/main.rs:5:13|5|y=&x;|^^borrowed value does not live long enough6|}|-`x`dropped herewhilestill borrowed7|8|println!("{}",y);|-borrow later used hereerror...