I am giving rust a try as a possible replacement for C++. I am reading through “The Book” (which is BTW excellent) and got surprised by variable binding shadowing.
Do I understand it right that it is possible to leak memory by shadowing the variable in the same scope? I mean in principle - I understand that the issue is easily solvable by clippy if need be.
Note that shadowing a name does not alter or destroy the value it was bound to, and the value will continue to exist until it goes out of scope, even if it is no longer accessible by any means.
let mut guess = String::new(); let mut guess = String::new(); // Is the first instance not accessible anymore but still in memory?