I'm having trouble with immutable borrow problem. immutable borrow occurs in "println!("{} ", s); " , but later I don't use the immutable borrow value any more.
I have:
fn main() {
let mut s = String::from("hello");
let r3 = &mut s;
println!("{} ", s);
*r3 = String::from("hello world");
}
And it's complaining:
error[E0502]: cannot borrow `s` as immutable because it is also borrowed as mutable
--> src/main.rs:31:21
|
30 | let r3 = &mut s;
| ------ mutable borrow occurs here
31 | println!("{} ", s);
| ^ immutable borrow occurs here
32 | *r3 = String::from("hello world");
| --- mutable borrow later used here