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