The error occurs because the literal 4_000_000_000 exceeds the maximum value for a signed 32-bit integer (i32), which is 2_147_483_647. Rust defaults to i32 for integer literals unless specified otherwise.
To resolve this, explicitly specify the type as u32 (unsigned 32-bit integer) or u64 (unsigned 64-bit integer) for the range. Here’s the corrected code:
rustfn main() { for _ in 0..4_000_000_000u32 {} }
or
rustfn main() { for _ in 0..4_000_000_000u64 {} }
This tells Rust to treat the literal as an unsigned integer, which can hold the value 4_000_000_000.
Vibe can make mistakes. Check answers. Learn more