Add tests
This commit is contained in:
parent
b0889cb4ed
commit
c5e17021cc
60
tests/ui/match/validate-range-endpoints.rs
Normal file
60
tests/ui/match/validate-range-endpoints.rs
Normal file
@ -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.. => {}
|
||||
}
|
||||
}
|
84
tests/ui/match/validate-range-endpoints.stderr
Normal file
84
tests/ui/match/validate-range-endpoints.stderr
Normal file
@ -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`.
|
Loading…
Reference in New Issue
Block a user