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