Section: Chapter 3.1 - Variables and Mutability
URL: https://rust-book.cs.brown.edu/ch03-01-variables-and-mutability.html
Current wording:
In the section explaining the compile-time error for the following code:
let mut spaces = " ";
spaces = spaces.len();
The book states: "The error says we’re not allowed to mutate a variable’s type:"
Problem:
This explanation is imprecise and potentially misleading. The actual error (E0308) is a type mismatch — the code attempts to assign a usize value to a variable of type &str. Rust's type system does not prevent changing a variable's type in general; in fact, shadowing (let spaces = spaces.len();) allows exactly that.
The error is about incompatible types in an assignment, not about a blanket prohibition on type changes.
Suggested fix:
Change the explanation to something like:
"This error indicates that we cannot assign a value of type usize to a variable of type &str because their types are incompatible."
Which translates to:
"This error shows that we cannot assign a value of type usize to a variable of type &str, because their types do not match."
This accurately describes the mismatch while also being consistent with Rust's shadowing feature.
Section: Chapter 3.1 - Variables and Mutability
URL: https://rust-book.cs.brown.edu/ch03-01-variables-and-mutability.html
Current wording:
In the section explaining the compile-time error for the following code:
let mut spaces = " ";
spaces = spaces.len();
The book states: "The error says we’re not allowed to mutate a variable’s type:"
Problem:
This explanation is imprecise and potentially misleading. The actual error (E0308) is a type mismatch — the code attempts to assign a usize value to a variable of type &str. Rust's type system does not prevent changing a variable's type in general; in fact, shadowing (let spaces = spaces.len();) allows exactly that.
The error is about incompatible types in an assignment, not about a blanket prohibition on type changes.
Suggested fix:
Change the explanation to something like:
"This error indicates that we cannot assign a value of type usize to a variable of type &str because their types are incompatible."
Which translates to:
"This error shows that we cannot assign a value of type usize to a variable of type &str, because their types do not match."
This accurately describes the mismatch while also being consistent with Rust's shadowing feature.