[package]
name = "Learn"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
[profile.dev]
overflow-checks=false
[profile.release]
overflow-checks=false
Overflow-checks only determines if there are runtime overflow checks. What happens at compile time is distinct. A compiler error is not the same as a runtime panic.
I think the expectation is that the 255u8+255u8 would get evaluated at compile time, being a constant expression, and produce the same compilation error in both the println!and `let´ statements.
But it does not. Try it to see. Why the difference?
Hmm... OK, so that moves the question to why is one 225u8+255u8 evaluated at compile time but the other 225u8+255u8 not? They look exactly the same, so why not?
Interestingly you can do this and get the same behavior:
let x = &(225u8+255u8);
So that then begs the question of why is taking the reference runtime vs compile time?
Edit:
For clarity, 'runtime vs compile time' might be a bit misleading. In Debug mode, this is compile time checked just like any other arithmetic operation. In Release mode, or with
overflow-checks=false
it is not. This makes it the same as any other runtime evaluated expression.
So the question is more like "Why isn't this treated as a compile time constant expression?"
Part of the reason we're adding const { … } is that the rules for that got super complicated. So we're winding them back as much as we can again, and asking people to request it when they actually want it using const { … } around the expression in question.