1 #![feature(precise_pointer_size_matching)]
2 #![feature(exclusive_range_pattern)]
4 #![deny(unreachable_patterns)]
6 use std::{char, u8, u16, u32, u64, u128, i8, i16, i32, i64, i128};
11 // A single range covering the entire domain.
16 // A combination of ranges and values.
17 // These are currently allowed to be overlapping.
23 200 => {} //~ ERROR unreachable pattern
27 // An incomplete set of values.
28 match x { //~ ERROR non-exhaustive patterns
32 // A more incomplete set of values.
33 match x { //~ ERROR non-exhaustive patterns
41 match x { //~ ERROR non-exhaustive patterns
44 -2..=20 => {} //~ ERROR unreachable pattern
48 // Let's test other types too!
49 let c: char = '\u{0}';
51 '\u{0}' ..= char::MAX => {} // ok
54 // We can actually get away with just covering the
55 // following two ranges, which correspond to all
56 // valid Unicode Scalar Values.
58 '\u{0000}' ..= '\u{D7FF}' => {}
59 '\u{E000}' ..= '\u{10_FFFF}' => {}
63 0 ..= u16::MAX => {} // ok
67 0 ..= u32::MAX => {} // ok
71 0 ..= u64::MAX => {} // ok
75 0 ..= u128::MAX => {} // ok
79 -128 ..= 127 => {} // ok
82 match 0i8 { //~ ERROR non-exhaustive patterns
87 i16::MIN ..= i16::MAX => {} // ok
90 match 0i16 { //~ ERROR non-exhaustive patterns
96 i32::MIN ..= i32::MAX => {} // ok
100 i64::MIN ..= i64::MAX => {} // ok
104 i128::MIN ..= i128::MAX => {} // ok
107 // Make sure that guards don't factor into the exhaustiveness checks.
108 match 0u8 { //~ ERROR non-exhaustive patterns
110 128 ..= 255 if true => {}
115 128 ..= 255 if false => {}
116 128 ..= 255 => {} // ok, because previous arm was guarded
119 // Now things start getting a bit more interesting. Testing products!
120 match (0u8, Some(())) { //~ ERROR non-exhaustive patterns
125 match (0u8, true) { //~ ERROR non-exhaustive patterns
126 (0 ..= 125, false) => {}
127 (128 ..= 255, false) => {}
128 (0 ..= 255, true) => {}
131 match (0u8, true) { // ok
132 (0 ..= 125, false) => {}
133 (128 ..= 255, false) => {}
134 (0 ..= 255, true) => {}
135 (125 .. 128, false) => {}
144 const LIM: u128 = u128::MAX - 1;
145 match 0u128 { //~ ERROR non-exhaustive patterns
149 match 0u128 { //~ ERROR non-exhaustive patterns
153 match 0u128 { //~ ERROR non-exhaustive patterns
154 4 ..= u128::MAX => {}