Answers for "rust•armanazi•error•[E0106]: missing lifetime specifier --> src/main.rs:5:20 | 5 | fn dangle() -> &i32 { // dangle returns a reference to a String | ^ expected named lifetime parameter"

0

rust•armanazi•error•[E0106]: missing lifetime specifier --> src/main.rs:5:20 | 5 | fn dangle() -> &i32 { // dangle returns a reference to a String | ^ expected named lifetime parameter

help: consider using the `'static` lifetime
  |
5 |     fn dangle() -> &'static i32 { // dangle returns a reference to a String
Posted by: Guest on March-19-2022
0

rust•armanazi•error•[E0106]: missing lifetime specifier --> src/main.rs:5:16 | 5 | fn dangle() -> &String { | ^ expected named lifetime parameter

fn no_dangle() -> String {
    let s = String::from("hello");

    s
}
This works without any problems. Ownership is moved out, and nothing is deallocated.
Posted by: Guest on March-19-2022

Code answers related to "rust•armanazi•error•[E0106]: missing lifetime specifier --> src/main.rs:5:20 | 5 | fn dangle() -> &i32 { // dangle returns a reference to a String | ^ expected named lifetime parameter"

Browse Popular Code Answers by Language