From c5e17021cc8ce4a3595100b7d96ed5b32b611d63 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 10 Oct 2023 20:28:08 +0200 Subject: [PATCH] Add tests --- tests/ui/match/validate-range-endpoints.rs | 60 +++++++++++++ .../ui/match/validate-range-endpoints.stderr | 84 +++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 tests/ui/match/validate-range-endpoints.rs create mode 100644 tests/ui/match/validate-range-endpoints.stderr diff --git a/tests/ui/match/validate-range-endpoints.rs b/tests/ui/match/validate-range-endpoints.rs new file mode 100644 index 00000000000..3fe431e2f62 --- /dev/null +++ b/tests/ui/match/validate-range-endpoints.rs @@ -0,0 +1,60 @@ +#![feature(exclusive_range_pattern)] +#![feature(inline_const_pat)] +#![allow(incomplete_features)] +#![allow(overlapping_range_endpoints)] + +fn main() { + const TOO_BIG: u8 = 256; + match 0u8 { + 1..257 => {} + //~^ ERROR literal out of range + 1..=256 => {} + //~^ ERROR literal out of range + + // overflow is detected in a later pass for these + 0..257 => {} + 0..=256 => {} + 256..=100 => {} + + // There isn't really a way to detect these + 1..=TOO_BIG => {} + //~^ ERROR lower range bound must be less than or equal to upper + 1..=const { 256 } => {} + //~^ ERROR lower range bound must be less than or equal to upper + _ => {} + } + + match 0u64 { + 10000000000000000000..=99999999999999999999 => {} + //~^ ERROR literal out of range + _ => {} + } + + // FIXME: error message is confusing + match 0i8 { + 0..129 => {} + //~^ ERROR lower range bound must be less than upper + 0..=128 => {} + //~^ ERROR lower range bound must be less than or equal to upper + -129..0 => {} + //~^ ERROR lower range bound must be less than upper + -10000..=-20 => {} + //~^ ERROR lower range bound must be less than or equal to upper + + // overflow is detected in a later pass for these + 128..=0 => {} + 0..-129 => {} + -10000..=0 => {} + _ => {} + } + + // FIXME: error message is confusing + match 0i8 { + //~^ ERROR `i8::MIN..=-17_i8` and `1_i8..=i8::MAX` not covered + -10000..=0 => {} + } + match 0i8 { + //~^ ERROR `i8::MIN..=-17_i8` not covered + -10000.. => {} + } +} diff --git a/tests/ui/match/validate-range-endpoints.stderr b/tests/ui/match/validate-range-endpoints.stderr new file mode 100644 index 00000000000..bed52f8a445 --- /dev/null +++ b/tests/ui/match/validate-range-endpoints.stderr @@ -0,0 +1,84 @@ +error: literal out of range for `u8` + --> $DIR/validate-range-endpoints.rs:9:12 + | +LL | 1..257 => {} + | ^^^ this value doesn't fit in `u8` whose maximum value is `255` + +error: literal out of range for `u8` + --> $DIR/validate-range-endpoints.rs:11:13 + | +LL | 1..=256 => {} + | ^^^ this value doesn't fit in `u8` whose maximum value is `255` + +error[E0030]: lower range bound must be less than or equal to upper + --> $DIR/validate-range-endpoints.rs:20:9 + | +LL | 1..=TOO_BIG => {} + | ^ lower bound larger than upper bound + +error[E0030]: lower range bound must be less than or equal to upper + --> $DIR/validate-range-endpoints.rs:22:9 + | +LL | 1..=const { 256 } => {} + | ^ lower bound larger than upper bound + +error: literal out of range for `u64` + --> $DIR/validate-range-endpoints.rs:28:32 + | +LL | 10000000000000000000..=99999999999999999999 => {} + | ^^^^^^^^^^^^^^^^^^^^ this value doesn't fit in `u64` whose maximum value is `18446744073709551615` + +error[E0579]: lower range bound must be less than upper + --> $DIR/validate-range-endpoints.rs:35:9 + | +LL | 0..129 => {} + | ^ + +error[E0030]: lower range bound must be less than or equal to upper + --> $DIR/validate-range-endpoints.rs:37:9 + | +LL | 0..=128 => {} + | ^ lower bound larger than upper bound + +error[E0579]: lower range bound must be less than upper + --> $DIR/validate-range-endpoints.rs:39:9 + | +LL | -129..0 => {} + | ^^^^ + +error[E0030]: lower range bound must be less than or equal to upper + --> $DIR/validate-range-endpoints.rs:41:9 + | +LL | -10000..=-20 => {} + | ^^^^^^ lower bound larger than upper bound + +error[E0004]: non-exhaustive patterns: `i8::MIN..=-17_i8` and `1_i8..=i8::MAX` not covered + --> $DIR/validate-range-endpoints.rs:52:11 + | +LL | match 0i8 { + | ^^^ patterns `i8::MIN..=-17_i8` and `1_i8..=i8::MAX` not covered + | + = note: the matched value is of type `i8` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms + | +LL ~ -10000..=0 => {}, +LL + i8::MIN..=-17_i8 | 1_i8..=i8::MAX => todo!() + | + +error[E0004]: non-exhaustive patterns: `i8::MIN..=-17_i8` not covered + --> $DIR/validate-range-endpoints.rs:56:11 + | +LL | match 0i8 { + | ^^^ pattern `i8::MIN..=-17_i8` not covered + | + = note: the matched value is of type `i8` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +LL ~ -10000.. => {}, +LL + i8::MIN..=-17_i8 => todo!() + | + +error: aborting due to 11 previous errors + +Some errors have detailed explanations: E0004, E0030, E0579. +For more information about an error, try `rustc --explain E0004`.