Skip to content

Commit a1ab83f

Browse files
committed
Add tests
1 parent b0889cb commit a1ab83f

File tree

2 files changed

+144
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)