Closed
Description
How is one supposed to create a range which includes the maximum value as it's upper bound?
E.g. if I wish to create the range 100 to 255 inclusive for a u8
, I need use the notation 100..256
:
fn main() {
let r: std::ops::Range<u8> = 100..256;
println!("{:?}", r);
}
The output of which is:
100..0
(we do get a warning when we compile though)
test.rs:2:39: 2:42 warning: literal out of range for u8, #[warn(overflowing_literals)] on by default
test.rs:2 let r: std::ops::Range<u8> = 100..256;
^~~
I understand why this is happening based on the implementation of Range, and I'm not sure how one would fix it without changing Range to use an inclusive upper bound (even if the notation stays as is). Maybe a better warning might be of use if I can't be solved?
Metadata
Metadata
Assignees
Labels
No labels