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