cognitive-engineering-lab / rust-book

The Rust Programming Language: Experimental Edition
https://rust-book.cs.brown.edu
Other
503 stars 82 forks source link

mutating a variable’s type does not give an error #170

Closed block0xhash closed 3 months ago

block0xhash commented 3 months ago

Hi It says here https://rust-book.cs.brown.edu/ch03-01-variables-and-mutability.html that:

if we try to use mut for a variable that is shadowed you will get an error: image

however I got a warning instead and the code runs:

image

~/rustbook/variables$ cargo --version
cargo 1.76.0 (c84b36747 2024-01-18)
~/rustbook/variables$ rustc --version
rustc 1.76.0 (07dca489a 2024-02-04
willcrichton commented 3 months ago

The book's snippet is not shadowing spaces, but rather re-assigning to it. Note that there is no let keyword on the second line.

block0xhash commented 3 months ago

Thanks Will. I get it now image