0

The rust book comes with this example. https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html

let spaces = "   ";
let spaces = spaces.len();

So then the variable has not only changed its value, but also the type.

Earlier in the chapter it states plenty of reasons to not allow changing the value when immutable. So what is the point if you can redeclare? Isn't it causing the same issues that the compiler usually tries to avoid?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Franco Pan
  • 128
  • 2
  • 11
  • [What is the rationale behind allowing variable shadowing in Rust?](https://stackoverflow.com/questions/59860476/what-is-the-rationale-behind-allowing-variable-shadowing-in-rust) – John Kugelman Mar 29 '23 at 02:08

0 Answers0