Skip to content

Commit 891a736

Browse files
committed
Test parsing and recovery of all sorts of range patterns.
1 parent f6c8234 commit 891a736

File tree

2 files changed

+949
-0
lines changed

2 files changed

+949
-0
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
// Here we test all kinds of range patterns in terms of parsing / recovery.
2+
// We want to ensure that:
3+
// 1. Things parse as they should.
4+
// 2. Or at least we have parser recovery if they don't.
5+
6+
#![feature(exclusive_range_pattern)]
7+
#![deny(ellipsis_inclusive_range_patterns)]
8+
9+
fn main() {}
10+
11+
const X: u8 = 0;
12+
const Y: u8 = 3;
13+
14+
fn exclusive_from_to() {
15+
if let 0..3 = 0 {} // OK.
16+
if let 0..Y = 0 {} // OK.
17+
if let X..3 = 0 {} // OK.
18+
if let X..Y = 0 {} // OK.
19+
if let true..Y = 0 {} //~ ERROR only char and numeric types
20+
if let X..true = 0 {} //~ ERROR only char and numeric types
21+
if let .0..Y = 0 {} //~ ERROR mismatched types
22+
//~^ ERROR float literals must have an integer part
23+
if let X.. .0 = 0 {} //~ ERROR mismatched types
24+
//~^ ERROR float literals must have an integer part
25+
}
26+
27+
fn inclusive_from_to() {
28+
if let 0..=3 = 0 {} // OK.
29+
if let 0..=Y = 0 {} // OK.
30+
if let X..=3 = 0 {} // OK.
31+
if let X..=Y = 0 {} // OK.
32+
if let true..=Y = 0 {} //~ ERROR only char and numeric types
33+
if let X..=true = 0 {} //~ ERROR only char and numeric types
34+
if let .0..=Y = 0 {} //~ ERROR mismatched types
35+
//~^ ERROR float literals must have an integer part
36+
if let X..=.0 = 0 {} //~ ERROR mismatched types
37+
//~^ ERROR float literals must have an integer part
38+
}
39+
40+
fn inclusive2_from_to() {
41+
if let 0...3 = 0 {} //~ ERROR `...` range patterns are deprecated
42+
if let 0...Y = 0 {} //~ ERROR `...` range patterns are deprecated
43+
if let X...3 = 0 {} //~ ERROR `...` range patterns are deprecated
44+
if let X...Y = 0 {} //~ ERROR `...` range patterns are deprecated
45+
if let true...Y = 0 {} //~ ERROR only char and numeric types
46+
//~^ ERROR `...` range patterns are deprecated
47+
if let X...true = 0 {} //~ ERROR only char and numeric types
48+
//~^ ERROR `...` range patterns are deprecated
49+
if let .0...Y = 0 {} //~ ERROR mismatched types
50+
//~^ ERROR float literals must have an integer part
51+
//~| ERROR `...` range patterns are deprecated
52+
if let X... .0 = 0 {} //~ ERROR mismatched types
53+
//~^ ERROR float literals must have an integer part
54+
//~| ERROR `...` range patterns are deprecated
55+
}
56+
57+
fn exclusive_from() {
58+
if let 0.. = 0 {} //~ ERROR only char and numeric types
59+
//~^ ERROR arbitrary expressions aren't allowed in patterns
60+
//~| ERROR `X..` range patterns are not supported
61+
if let X.. = 0 {} //~ ERROR only char and numeric types
62+
//~^ ERROR arbitrary expressions aren't allowed in patterns
63+
//~| ERROR `X..` range patterns are not supported
64+
if let true.. = 0 {} //~ ERROR only char and numeric types
65+
//~^ ERROR arbitrary expressions aren't allowed in patterns
66+
//~| ERROR `X..` range patterns are not supported
67+
if let .0.. = 0 {} //~ ERROR only char and numeric types
68+
//~^ ERROR arbitrary expressions aren't allowed in patterns
69+
//~| ERROR `X..` range patterns are not supported
70+
//~| ERROR float literals must have an integer part
71+
}
72+
73+
fn inclusive_from() {
74+
if let 0..= = 0 {} //~ ERROR only char and numeric types
75+
//~^ ERROR arbitrary expressions aren't allowed in patterns
76+
//~| ERROR `X..=` range patterns are not supported
77+
if let X..= = 0 {} //~ ERROR only char and numeric types
78+
//~^ ERROR arbitrary expressions aren't allowed in patterns
79+
//~| ERROR `X..=` range patterns are not supported
80+
if let true..= = 0 {} //~ ERROR only char and numeric types
81+
//~^ ERROR arbitrary expressions aren't allowed in patterns
82+
//~| ERROR `X..=` range patterns are not supported
83+
if let .0..= = 0 {} //~ ERROR only char and numeric types
84+
//~^ ERROR arbitrary expressions aren't allowed in patterns
85+
//~| ERROR `X..=` range patterns are not supported
86+
//~| ERROR float literals must have an integer part
87+
}
88+
89+
fn inclusive2_from() {
90+
if let 0... = 0 {} //~ ERROR only char and numeric types
91+
//~^ ERROR arbitrary expressions aren't allowed in patterns
92+
//~| ERROR `X...` range patterns are not supported
93+
//~| ERROR `...` range patterns are deprecated
94+
if let X... = 0 {} //~ ERROR only char and numeric types
95+
//~^ ERROR arbitrary expressions aren't allowed in patterns
96+
//~| ERROR `X...` range patterns are not supported
97+
//~| ERROR `...` range patterns are deprecated
98+
if let true... = 0 {} //~ ERROR only char and numeric types
99+
//~^ ERROR arbitrary expressions aren't allowed in patterns
100+
//~| ERROR `X...` range patterns are not supported
101+
//~| ERROR `...` range patterns are deprecated
102+
if let .0... = 0 {} //~ ERROR only char and numeric types
103+
//~^ ERROR arbitrary expressions aren't allowed in patterns
104+
//~| ERROR `X...` range patterns are not supported
105+
//~| ERROR float literals must have an integer part
106+
//~| ERROR `...` range patterns are deprecated
107+
}
108+
109+
fn exclusive_to() {
110+
if let ..0 = 0 {} //~ ERROR only char and numeric types
111+
//~^ ERROR arbitrary expressions aren't allowed in patterns
112+
//~| ERROR `..X` range patterns are not supported
113+
if let ..Y = 0 {} //~ ERROR only char and numeric types
114+
//~^ ERROR arbitrary expressions aren't allowed in patterns
115+
//~| ERROR `..X` range patterns are not supported
116+
if let ..true = 0 {} //~ ERROR only char and numeric types
117+
//~^ ERROR arbitrary expressions aren't allowed in patterns
118+
//~| ERROR `..X` range patterns are not supported
119+
if let .. .0 = 0 {} //~ ERROR only char and numeric types
120+
//~^ ERROR arbitrary expressions aren't allowed in patterns
121+
//~| ERROR `..X` range patterns are not supported
122+
//~| ERROR float literals must have an integer part
123+
}
124+
125+
fn inclusive_to() {
126+
if let ..=3 = 0 {} //~ ERROR only char and numeric types
127+
//~^ ERROR arbitrary expressions aren't allowed in patterns
128+
//~| ERROR `..=X` range patterns are not supported
129+
if let ..=Y = 0 {} //~ ERROR only char and numeric types
130+
//~^ ERROR arbitrary expressions aren't allowed in patterns
131+
//~| ERROR `..=X` range patterns are not supported
132+
if let ..=true = 0 {} //~ ERROR only char and numeric types
133+
//~^ ERROR arbitrary expressions aren't allowed in patterns
134+
//~| ERROR `..=X` range patterns are not supported
135+
if let ..=.0 = 0 {} //~ ERROR only char and numeric types
136+
//~^ ERROR arbitrary expressions aren't allowed in patterns
137+
//~| ERROR `..=X` range patterns are not supported
138+
//~| ERROR float literals must have an integer part
139+
}
140+
141+
fn inclusive2_to() {
142+
if let ...3 = 0 {} //~ ERROR only char and numeric types
143+
//~^ ERROR arbitrary expressions aren't allowed in patterns
144+
//~| ERROR `...X` range patterns are not supported
145+
//~| ERROR `...` range patterns are deprecated
146+
if let ...Y = 0 {} //~ ERROR only char and numeric types
147+
//~^ ERROR arbitrary expressions aren't allowed in patterns
148+
//~| ERROR `...X` range patterns are not supported
149+
//~| ERROR `...` range patterns are deprecated
150+
if let ...true = 0 {} //~ ERROR only char and numeric types
151+
//~^ ERROR arbitrary expressions aren't allowed in patterns
152+
//~| ERROR `...X` range patterns are not supported
153+
//~| ERROR `...` range patterns are deprecated
154+
if let ....3 = 0 {} //~ ERROR only char and numeric types
155+
//~^ ERROR arbitrary expressions aren't allowed in patterns
156+
//~| ERROR `...X` range patterns are not supported
157+
//~| ERROR float literals must have an integer part
158+
//~| ERROR `...` range patterns are deprecated
159+
}

0 commit comments

Comments
 (0)