Skip to content

Commit 97185da

Browse files
committed
Add tests
1 parent b0889cb commit 97185da

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#![feature(exclusive_range_pattern)]
2+
#![allow(overlapping_range_endpoints)]
3+
#![allow(illegal_floating_point_literal_pattern)]
4+
5+
fn main() {
6+
match 0u8 {
7+
1..257 => {}
8+
//~^ ERROR literal out of range
9+
1..=256 => {}
10+
//~^ ERROR literal out of range
11+
12+
// overflow is detected in a later pass for these
13+
0..257 => {}
14+
0..=256 => {}
15+
256..=100 => {}
16+
_ => {}
17+
}
18+
19+
match 0usize {
20+
10000000000000000000..=99999999999999999999 => {}
21+
//~^ ERROR literal out of range
22+
_ => {}
23+
}
24+
25+
// FIXME: error message is confusing
26+
match 0i8 {
27+
0..129 => {}
28+
//~^ ERROR lower range bound must be less than upper
29+
0..=128 => {}
30+
//~^ ERROR lower range bound must be less than or equal to upper
31+
-129..0 => {}
32+
//~^ ERROR lower range bound must be less than upper
33+
-10000..=-20 => {}
34+
//~^ ERROR lower range bound must be less than or equal to upper
35+
36+
// overflow is detected in a later pass for these
37+
128..=0 => {}
38+
0..-129 => {}
39+
-10000..=0 => {}
40+
_ => {}
41+
}
42+
43+
// FIXME: error message is confusing
44+
match 0i8 {
45+
//~^ ERROR `i8::MIN..=-17_i8` and `1_i8..=i8::MAX` not covered
46+
-10000..=0 => {}
47+
}
48+
match 0i8 {
49+
//~^ ERROR `i8::MIN..=-17_i8` not covered
50+
-10000.. => {}
51+
}
52+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
error: literal out of range for `u8`
2+
--> $DIR/validate-range-endpoints.rs:7:12
3+
|
4+
LL | 1..257 => {}
5+
| ^^^ this value doesn't fit in `u8` whose maximum value is `255`
6+
7+
error: literal out of range for `u8`
8+
--> $DIR/validate-range-endpoints.rs:9:13
9+
|
10+
LL | 1..=256 => {}
11+
| ^^^ this value doesn't fit in `u8` whose maximum value is `255`
12+
13+
error: literal out of range for `usize`
14+
--> $DIR/validate-range-endpoints.rs:20:32
15+
|
16+
LL | 10000000000000000000..=99999999999999999999 => {}
17+
| ^^^^^^^^^^^^^^^^^^^^ this value doesn't fit in `usize` whose maximum value is `18446744073709551615`
18+
19+
error[E0579]: lower range bound must be less than upper
20+
--> $DIR/validate-range-endpoints.rs:27:9
21+
|
22+
LL | 0..129 => {}
23+
| ^
24+
25+
error[E0030]: lower range bound must be less than or equal to upper
26+
--> $DIR/validate-range-endpoints.rs:29:9
27+
|
28+
LL | 0..=128 => {}
29+
| ^ lower bound larger than upper bound
30+
31+
error[E0579]: lower range bound must be less than upper
32+
--> $DIR/validate-range-endpoints.rs:31:9
33+
|
34+
LL | -129..0 => {}
35+
| ^^^^
36+
37+
error[E0030]: lower range bound must be less than or equal to upper
38+
--> $DIR/validate-range-endpoints.rs:33:9
39+
|
40+
LL | -10000..=-20 => {}
41+
| ^^^^^^ lower bound larger than upper bound
42+
43+
error[E0004]: non-exhaustive patterns: `i8::MIN..=-17_i8` and `1_i8..=i8::MAX` not covered
44+
--> $DIR/validate-range-endpoints.rs:44:11
45+
|
46+
LL | match 0i8 {
47+
| ^^^ patterns `i8::MIN..=-17_i8` and `1_i8..=i8::MAX` not covered
48+
|
49+
= note: the matched value is of type `i8`
50+
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
51+
|
52+
LL ~ -10000..=0 => {},
53+
LL + i8::MIN..=-17_i8 | 1_i8..=i8::MAX => todo!()
54+
|
55+
56+
error[E0004]: non-exhaustive patterns: `i8::MIN..=-17_i8` not covered
57+
--> $DIR/validate-range-endpoints.rs:48:11
58+
|
59+
LL | match 0i8 {
60+
| ^^^ pattern `i8::MIN..=-17_i8` not covered
61+
|
62+
= note: the matched value is of type `i8`
63+
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
64+
|
65+
LL ~ -10000.. => {},
66+
LL + i8::MIN..=-17_i8 => todo!()
67+
|
68+
69+
error: aborting due to 9 previous errors
70+
71+
Some errors have detailed explanations: E0004, E0030, E0579.
72+
For more information about an error, try `rustc --explain E0004`.

0 commit comments

Comments
 (0)