From c5fdff26b58704f5b346ab2c96ea784f959eb3dd Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 27 Apr 2019 12:45:17 +0100 Subject: [PATCH] Add a test for overflowing endpoints --- .../ui/lint/lint-range-endpoint-overflow.rs | 15 +++++++++ .../lint/lint-range-endpoint-overflow.stderr | 32 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/test/ui/lint/lint-range-endpoint-overflow.rs create mode 100644 src/test/ui/lint/lint-range-endpoint-overflow.stderr diff --git a/src/test/ui/lint/lint-range-endpoint-overflow.rs b/src/test/ui/lint/lint-range-endpoint-overflow.rs new file mode 100644 index 00000000000..36fcbd36c6a --- /dev/null +++ b/src/test/ui/lint/lint-range-endpoint-overflow.rs @@ -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::>(); + range_b.collect::>(); + range_c.collect::>(); + range_d.collect::>(); + range_e.collect::>(); +} diff --git a/src/test/ui/lint/lint-range-endpoint-overflow.stderr b/src/test/ui/lint/lint-range-endpoint-overflow.stderr new file mode 100644 index 00000000000..56568765c1c --- /dev/null +++ b/src/test/ui/lint/lint-range-endpoint-overflow.stderr @@ -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 +