1 #![feature(exclusive_range_pattern)]
2 #![feature(assoc_char_consts)]
3 #![deny(unreachable_patterns)]
6 ($s:expr, $($t:tt)+) => {
7 match $s { $($t)+ => {} }
11 macro_rules! test_int {
12 ($s:expr, $min:path, $max:path) => {
14 m!($s, $min..5 | 5..=$max);
15 m!($s, $min..=4 | 5..=$max);
16 m!($s, $min..$max | $max);
17 m!(($s, true), ($min..5, true) | (5..=$max, true) | ($min..=$max, false));
22 test_int!(0u8, u8::MIN, u8::MAX);
23 test_int!(0u16, u16::MIN, u16::MAX);
24 test_int!(0u32, u32::MIN, u32::MAX);
25 test_int!(0u64, u64::MIN, u64::MAX);
26 test_int!(0u128, u128::MIN, u128::MAX);
28 test_int!(0i8, i8::MIN, i8::MAX);
29 test_int!(0i16, i16::MIN, i16::MAX);
30 test_int!(0i32, i32::MIN, i32::MAX);
31 test_int!(0i64, i64::MIN, i64::MAX);
32 test_int!(0i128, i128::MIN, i128::MAX);
34 m!('a', '\u{0}'..=char::MAX);
35 m!('a', '\u{0}'..='\u{10_FFFF}');
36 // We can get away with just covering the following two ranges, which correspond to all valid
37 // Unicode Scalar Values.
38 m!('a', '\u{0}'..='\u{D7FF}' | '\u{E000}'..=char::MAX);
39 m!('a', '\u{0}'..'\u{D7FF}' | '\u{D7FF}' | '\u{E000}'..=char::MAX);
43 let -2147483648..=2147483647 = 0i32;
44 let '\u{0000}'..='\u{10FFFF}' = 'v';
47 m!(0u8, 0..255); //~ ERROR non-exhaustive patterns
48 m!(0u8, 0..=254); //~ ERROR non-exhaustive patterns
49 m!(0u8, 1..=255); //~ ERROR non-exhaustive patterns
50 m!(0u8, 0..42 | 43..=255); //~ ERROR non-exhaustive patterns
51 m!(0i8, -128..127); //~ ERROR non-exhaustive patterns
52 m!(0i8, -128..=126); //~ ERROR non-exhaustive patterns
53 m!(0i8, -127..=127); //~ ERROR non-exhaustive patterns
54 match 0i8 { //~ ERROR non-exhaustive patterns
58 const ALMOST_MAX: u128 = u128::MAX - 1;
59 m!(0u128, 0..=ALMOST_MAX); //~ ERROR non-exhaustive patterns
60 m!(0u128, 0..=4); //~ ERROR non-exhaustive patterns
61 m!(0u128, 1..=u128::MAX); //~ ERROR non-exhaustive patterns
63 // More complicatedly (non-)exhaustive
69 match (0u8, true) { //~ ERROR non-exhaustive patterns
70 (0 ..= 125, false) => {}
71 (128 ..= 255, false) => {}
72 (0 ..= 255, true) => {}
74 match (0u8, true) { // ok
75 (0 ..= 125, false) => {}
76 (128 ..= 255, false) => {}
77 (0 ..= 255, true) => {}
78 (125 .. 128, false) => {}
81 (true, 0 ..= 255) => {}
82 (false, 0 ..= 125) => {}
83 (false, 128 ..= 255) => {}
84 (false, 125 .. 128) => {}
89 Some(128 ..= 255) => {}
90 Some(125 .. 128) => {}