I have these 2 pieces of code:
fn main() {
let mut x: int = 5;
x = 6;
println!("value {}", x);
}
With this code, the compiler will raise warning:
the value is never read at
let x: int = 5
But with the following code, the compiler doesn't.
struct Point {
x: int,
y: int,
}
fn main() {
let mut p = Point {x: 1i, y: 2i};
p.x = 5;
println!("value {}, {}", p.x, p.y);
}
Why does that happens? We never read the value when x = 1i
. Rather, we read the value at x = 5i
. So why the compiler doesn't raise warning like the code before?