1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
// Test various non-exhaustive matches for `X..`, `..=X` and `..X` ranges.
#![allow(non_contiguous_range_endpoints)]
fn main() {}
macro_rules! m {
($s:expr, $($t:tt)+) => {
match $s { $($t)+ => {} }
}
}
fn floats() {
m!(0f32, f32::NEG_INFINITY..); //~ ERROR non-exhaustive patterns: `_` not covered
m!(0f32, ..f32::INFINITY); //~ ERROR non-exhaustive patterns: `_` not covered
}
fn khar() {
const ALMOST_MAX: char = '\u{10fffe}';
const ALMOST_MIN: char = '\u{1}';
const VAL: char = 'a';
const VAL_1: char = 'b';
const VAL_2: char = 'c';
m!('a', ..core::char::MAX); //~ ERROR non-exhaustive patterns
m!('a', ..ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!('a', ALMOST_MIN..); //~ ERROR non-exhaustive patterns
m!('a', ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!('a', ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns
m!('a', ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns
}
mod unsigned {
fn u8() {
const ALMOST_MAX: u8 = u8::MAX - 1;
const ALMOST_MIN: u8 = u8::MIN + 1;
const VAL: u8 = 42;
const VAL_1: u8 = VAL + 1;
const VAL_2: u8 = VAL + 2;
m!(0, ..u8::MAX); //~ ERROR non-exhaustive patterns
m!(0, ..ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!(0, ALMOST_MIN..); //~ ERROR non-exhaustive patterns
m!(0, ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!(0, ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns
m!(0, ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns
}
fn u16() {
const ALMOST_MAX: u16 = u16::MAX - 1;
const ALMOST_MIN: u16 = u16::MIN + 1;
const VAL: u16 = 42;
const VAL_1: u16 = VAL + 1;
const VAL_2: u16 = VAL + 2;
m!(0, ..u16::MAX); //~ ERROR non-exhaustive patterns
m!(0, ..ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!(0, ALMOST_MIN..); //~ ERROR non-exhaustive patterns
m!(0, ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!(0, ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns
m!(0, ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns
}
fn u32() {
const ALMOST_MAX: u32 = u32::MAX - 1;
const ALMOST_MIN: u32 = u32::MIN + 1;
const VAL: u32 = 42;
const VAL_1: u32 = VAL + 1;
const VAL_2: u32 = VAL + 2;
m!(0, ..u32::MAX); //~ ERROR non-exhaustive patterns
m!(0, ..ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!(0, ALMOST_MIN..); //~ ERROR non-exhaustive patterns
m!(0, ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!(0, ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns
m!(0, ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns
}
fn u64() {
const ALMOST_MAX: u64 = u64::MAX - 1;
const ALMOST_MIN: u64 = u64::MIN + 1;
const VAL: u64 = 42;
const VAL_1: u64 = VAL + 1;
const VAL_2: u64 = VAL + 2;
m!(0, ..u64::MAX); //~ ERROR non-exhaustive patterns
m!(0, ..ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!(0, ALMOST_MIN..); //~ ERROR non-exhaustive patterns
m!(0, ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!(0, ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns
m!(0, ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns
}
fn u128() {
const ALMOST_MAX: u128 = u128::MAX - 1;
const ALMOST_MIN: u128 = u128::MIN + 1;
const VAL: u128 = 42;
const VAL_1: u128 = VAL + 1;
const VAL_2: u128 = VAL + 2;
m!(0, ..u128::MAX); //~ ERROR non-exhaustive patterns
m!(0, ..ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!(0, ALMOST_MIN..); //~ ERROR non-exhaustive patterns
m!(0, ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!(0, ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns
m!(0, ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns
}
}
mod signed {
fn i8() {
const ALMOST_MAX: i8 = i8::MAX - 1;
const ALMOST_MIN: i8 = i8::MIN + 1;
const VAL: i8 = 42;
const VAL_1: i8 = VAL + 1;
const VAL_2: i8 = VAL + 2;
m!(0, ..i8::MAX); //~ ERROR non-exhaustive patterns
m!(0, ..ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!(0, ALMOST_MIN..); //~ ERROR non-exhaustive patterns
m!(0, ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!(0, ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns
m!(0, ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns
}
fn i16() {
const ALMOST_MAX: i16 = i16::MAX - 1;
const ALMOST_MIN: i16 = i16::MIN + 1;
const VAL: i16 = 42;
const VAL_1: i16 = VAL + 1;
const VAL_2: i16 = VAL + 2;
m!(0, ..i16::MAX); //~ ERROR non-exhaustive patterns
m!(0, ..ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!(0, ALMOST_MIN..); //~ ERROR non-exhaustive patterns
m!(0, ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!(0, ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns
m!(0, ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns
}
fn i32() {
const ALMOST_MAX: i32 = i32::MAX - 1;
const ALMOST_MIN: i32 = i32::MIN + 1;
const VAL: i32 = 42;
const VAL_1: i32 = VAL + 1;
const VAL_2: i32 = VAL + 2;
m!(0, ..i32::MAX); //~ ERROR non-exhaustive patterns
m!(0, ..ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!(0, ALMOST_MIN..); //~ ERROR non-exhaustive patterns
m!(0, ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!(0, ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns
m!(0, ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns
}
fn i64() {
const ALMOST_MAX: i64 = i64::MAX - 1;
const ALMOST_MIN: i64 = i64::MIN + 1;
const VAL: i64 = 42;
const VAL_1: i64 = VAL + 1;
const VAL_2: i64 = VAL + 2;
m!(0, ..i64::MAX); //~ ERROR non-exhaustive patterns
m!(0, ..ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!(0, ALMOST_MIN..); //~ ERROR non-exhaustive patterns
m!(0, ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!(0, ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns
m!(0, ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns
}
fn i128() {
const ALMOST_MAX: i128 = i128::MAX - 1;
const ALMOST_MIN: i128 = i128::MIN + 1;
const VAL: i128 = 42;
const VAL_1: i128 = VAL + 1;
const VAL_2: i128 = VAL + 2;
m!(0, ..i128::MAX); //~ ERROR non-exhaustive patterns
m!(0, ..ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!(0, ALMOST_MIN..); //~ ERROR non-exhaustive patterns
m!(0, ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns
m!(0, ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns
m!(0, ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns
}
}
|