I'm reading through the Rust book, and it said the following in section 4.2:
At any given time, you can have either one mutable reference or any number of immutable references.
However, I was experimenting and discovered that I actually can have more than one mutable reference in the same scope without using any unsafe code:
fn make_mut(x: &mut i32) -> &mut i32 {
x
}
fn main() {
let mut i = 1;
let ir = &mut i;
let ir2 = make_mut(ir);
*ir2 = 2;
println!("{}", *ir);
}
Output:
2
What's going on here? Was the Rust book oversimplifying things? Is there a better source of information on the Rust borrow checker geared for inexperienced Rust programmers than the Rust book?