Add a test for overflowing endpoints

This commit is contained in:
varkor 2019-04-27 12:45:17 +01:00
parent 5ec2f5e87e
commit c5fdff26b5
2 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,15 @@
#![deny(overflowing_literals)]
fn main() {
let range_a = 0..256; //~ ERROR range endpoint is out of range for u8
let range_b = 0..=255; // ok
let range_c = 0..=256; //~ ERROR literal out of range for u8
let range_d = 256..5; //~ ERROR literal out of range for u8
let range_e = 0..257; //~ ERROR literal out of range for u8
range_a.collect::<Vec<u8>>();
range_b.collect::<Vec<u8>>();
range_c.collect::<Vec<u8>>();
range_d.collect::<Vec<u8>>();
range_e.collect::<Vec<u8>>();
}

View File

@ -0,0 +1,32 @@
error: range endpoint is out of range for u8
--> $DIR/lint-range-endpoint-overflow.rs:4:19
|
LL | let range_a = 0..256;
| ^^^^^^ help: use an inclusive range instead: `0..=255`
|
note: lint level defined here
--> $DIR/lint-range-endpoint-overflow.rs:1:9
|
LL | #![deny(overflowing_literals)]
| ^^^^^^^^^^^^^^^^^^^^
error: literal out of range for u8
--> $DIR/lint-range-endpoint-overflow.rs:6:23
|
LL | let range_c = 0..=256;
| ^^^
error: literal out of range for u8
--> $DIR/lint-range-endpoint-overflow.rs:7:19
|
LL | let range_d = 256..5;
| ^^^
error: literal out of range for u8
--> $DIR/lint-range-endpoint-overflow.rs:8:22
|
LL | let range_e = 0..257;
| ^^^
error: aborting due to 4 previous errors