6 ms·
If you need `0..=n`, you can't write `0..(n+1)` because that addition might overflow.
by dgrunwald 10mo ago
If you need `0..=n`, you can't write `0..(n+1)` because that addition might overflow.
- hgomersall 10mo agoI'm actually curious now how this is stored on `Range` in rust. I've certainly used ..= for exactly the reason you say, but as far as I'm aware `.end` on the range is the exclusive upper bound in all cases. What happens to `.end` in the overflowing case? Edit: it doesn't use Range for ..=, but rather RangeInclusive, which works fine.