rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.23k stars 12.7k forks source link

Allow exactly one mutable reference even after multiple immutable reference in same scope #128933

Open coderboyisongithub opened 2 months ago

coderboyisongithub commented 2 months ago

I think there is no issue with allowing one mutable reference with any number of immutable references in single scope.Having single mutable reference ensure there is one and only one mutator, while all immutable reference can yet access the mutated information from the variable.

veera-sivarajan commented 2 months ago

@rustbot label -needs-triage +C-discussion +A-borrow-checker

quixoticaxis commented 2 months ago

An example of why it won't work:

let iterator = vector.iter(); // immutable reference
vector.push(something); // mutable reference
// The vector could have re-allocated memory at this point, what does iterator look at?