mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
Add a test for overflowing endpoints
This commit is contained in:
parent
5ec2f5e87e
commit
c5fdff26b5
15
src/test/ui/lint/lint-range-endpoint-overflow.rs
Normal file
15
src/test/ui/lint/lint-range-endpoint-overflow.rs
Normal 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>>();
|
||||
}
|
32
src/test/ui/lint/lint-range-endpoint-overflow.stderr
Normal file
32
src/test/ui/lint/lint-range-endpoint-overflow.stderr
Normal 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
|
||||
|
Loading…
Reference in New Issue
Block a user