error[E0596]: cannot borrow `*some_string` as mutable, as it is behind a `&` reference --> src/main.rs:8:5 | 8 | some_string.push_str(", world"); | ^^^^^^^^^^^ `some_string` is a `&` reference, so the data it refers to cannot be borrowed as mutable | help: consider changing this to be a mutable reference | 7 | fn change(some_string: &mut String) { | +++
For more information about this error, try `rustc --explain E0596`. error: could not compile `hello_world` (bin "hello_world") due to 1 previous error
error[E0499]: cannot borrow `s` as mutable more than once at a time --> src/main.rs:5:14 | 4 | let r1 = &mut s; | ------ first mutable borrow occurs here 5 | let r2 = &mut s; | ^^^^^^ second mutable borrow occurs here 6 | 7 | println!("{}, {}", r1, r2); | -- first borrow later used here
For more information about this error, try `rustc --explain E0499`. error: could not compile `hello_world` (bin "hello_world") due to 1 previous error
error[E0502]: cannot borrow `s` as mutable because it is also borrowed as immutable --> src/main.rs:6:14 | 4 | let r1 = &s; // 没问题 | -- immutable borrow occurs here 5 | let r2 = &s; // 没问题 6 | let r3 = &mut s; // 大问题 | ^^^^^^ mutable borrow occurs here 7 | 8 | println!("{}, {}, and {}", r1, r2, r3); | -- immutable borrow later used here
For more information about this error, try `rustc --explain E0502`. error: could not compile `hello_world` (bin "hello_world") due to 1 previous error
error[E0106]: missing lifetime specifier --> src/main.rs:5:16 | 5 | fn dangle() -> &String { | ^ expected named 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 using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static` | 5 | fn dangle() -> &'static String { | +++++++ help: instead, you are more likely to want to return an owned value | 5 - fn dangle() -> &String { 5 + fn dangle() -> String { |
warning: unused variable: `reference_to_nothing` --> src/main.rs:2:9 | 2 | let reference_to_nothing = dangle(); | ^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_reference_to_nothing` | = note: `#[warn(unused_variables)]` on by default
error[E0515]: cannot return reference to local variable `s` --> src/main.rs:8:5 | 8 | &s | ^^ returns a reference to data owned by the current function
Some errors have detailed explanations: E0106, E0515. For more information about an error, try `rustc --explain E0106`. warning: `hello_world` (bin "hello_world") generated 1 warning error: could not compile `hello_world` (bin "hello_world") due to 2 previous errors; 1 warning emitted