I am learning rust, I am trying to understand references.
As per the rust's book -> https://doc.rust-lang.org/nightly/book/ch04-02-references-and-borrowing.html
It says
Note that a reference’s scope starts from where it is introduced
and continues through the last time that reference is used.
And goes on showing (from the book):
let mut s = String::from("hello");
let r1 = &s; // no problem
let r2 = &s; // no problem
println!("{} and {}", r1, r2);
// variables r1 and r2 will not be used after this point !! ... okay..?
BUT when I try to reproduce this, I get no error
My example (no error)
fn valid() {
let s = String::from("hi");
let r1 = &s; // valid immutable reference
let r2 = &s; // valid immutable reference
println!("{}, {}", r1, r2);
println!("{}", r1); // Why am I able to use r1 again here??
}