Closed
Description
I tried this code:
for i in 0..256 as u8 {
println!("{}", i);
}
I expected to see this happen:
printing all numbers from 0 to 255 (inclusive)
Instead, this happened:
error: literal out of range for `u8`
--> src/main.rs:10:17
|
10 | for i in 0..256 as u8 {
| ^^^
|
= note: the literal `256` does not fit into the type `u8` whose range is `0..=255`
= note: `#[deny(overflowing_literals)]` on by default
rustc --version --verbose
:
rustc 1.68.0 (2c8cc3432 2023-03-06)
binary: rustc
commit-hash: 2c8cc343237b8f7d5a3c3703e3a87f2eb2c54a74
commit-date: 2023-03-06
host: x86_64-unknown-linux-gnu
release: 1.68.0
LLVM version: 15.0.6