Open
Description
There is no compiler error, when trying to change the field of a const
struct.
I tried this code:
struct StructA {
pub a: u32,
}
const A: StructA = StructA{a: 0};
fn main() {
A.a = 10;
println!("{}", A.a);
}
I expected to see this happen:
Compiler error, because I try to change the value of a const
.
Instead, this happened:
The statement is just ignored. A.a = 10;
looks like the value of A.a
is set to 10
, since there is no compiler error, I expect this to happen.
Instead when printing the value of A.a
, it is still the initial value 0
Meta
rustc --version --verbose
:
rustc 1.24.0-nightly (8e7a609e6 2018-01-04)
binary: rustc
commit-hash: 8e7a609e635b728eba65d471c985ab462dc4cfc7
commit-date: 2018-01-04
host: x86_64-apple-darwin
release: 1.24.0-nightly
LLVM version: 4.0