$ cargo run Compiling chapter10 v0.1.0 (file:///projects/chapter10) error[E0597]: `x` does not live long enough --> src/main.rs:6:13 | 5 | let x = 5; | - binding `x` declared here 6 | r = &x; | ^^ borrowed value does not live long enough 7 | } | - `x` dropped here while still borrowed 8 | 9 | println!("r: {r}"); | --- borrow later used here
For more information about this error, try `rustc --explain E0597`. error: could not compile `chapter10` (bin "chapter10") due to 1 previous error
fnlongest(x: &str, y: &str) -> &str { if x.len() > y.len() { x } else { y } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
$ cargo run Compiling chapter10 v0.1.0 (file:///projects/chapter10) error[E0106]: missing lifetime specifier --> src/main.rs:9:33 | 9 | fn longest(x: &str, y: &str) -> &str { | ---- ---- ^ expected named lifetime parameter | = help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `x` or `y` help: consider introducing a named lifetime parameter | 9 | fn longest<'a>(x: &'a str, y: &'a str) -> &'a str { | ++++ ++ ++ ++ For more information about this error, try `rustc --explain E0106`. error: could not compile `chapter10` (bin "chapter10") due to 1 previous error
$ cargo run Compiling chapter10 v0.1.0 (file:///projects/chapter10) error[E0597]: `string2` does not live long enough --> src/main.rs:6:44 | 5 | let string2 = String::from("xyz"); | ------- binding `string2` declared here 6 | result = longest(string1.as_str(), string2.as_str()); | ^^^^^^^ borrowed value does not live long enough 7 | } | - `string2` dropped here while still borrowed 8 | println!("The longest string is {result}"); | -------- borrow later used here
For more information about this error, try `rustc --explain E0597`. error: could not compile `chapter10` (bin "chapter10") due to 1 previous error