Open jgnoonan opened 3 weeks ago
It looks like this still compiles with no errors, but the messages you are seeing are simply warnings. The first warning is that x is never used, which would be fixed by printing x after line 5 but might distract from the original intention of what the question is trying to teach. The second is saying that the original declared value x does not need to be mutable, which is true but also removes what I think was the original point of the question. Technically this question is still correct since this does compile (your compiler should have still produced a main binary file on your machine with this output). To prevent confusion, the question could specify that you can ignore warnings, but warnings themselves don't mean that it failed to compile.
main
branch to see if this has already been fixed, in this file:URL to the section(s) of the book with this problem: https://rust-book.cs.brown.edu/ch03-01-variables-and-mutability.html#shadowing
Description of the problem: According to the answer for question 1, the following code should compile:
fn main() { let mut x: u32 = 1; { let mut x = x; x += 2; } println!("{x}"); }
On my system using VSCode with Rust-Analyzer, it does not compile with the following errors:
x
is never read --> src/main.rs:6:5= help: maybe it is overwritten before being read? = note:
#[warn(unused_assignments)]
on by defaultmut
= note:
#[warn(unused_mut)]
on by defaultwarning:
variables
(bin "variables") generated 2 warnings (runcargo fix --bin "variables"
to apply 1 suggestion) Finisheddev
profile [unoptimized + debuginfo] target(s) in 0.14sSuggested fix: There should be a list of defaults that must be changed for the code to compile.