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.
6 #![feature(exclusive_range_pattern)]
7 #![deny(ellipsis_inclusive_range_patterns)]
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
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
40 fn inclusive2_from_to() {
42 //~^ ERROR `...` range patterns are deprecated
43 //~| WARN this is accepted in the current edition
45 //~^ ERROR `...` range patterns are deprecated
46 //~| WARN this is accepted in the current edition
48 //~^ ERROR `...` range patterns are deprecated
49 //~| WARN this is accepted in the current edition
51 //~^ ERROR `...` range patterns are deprecated
52 //~| WARN this is accepted in the current edition
53 if let true...Y = 0 {} //~ ERROR only `char` and numeric types
54 //~^ ERROR `...` range patterns are deprecated
55 //~| WARN this is accepted in the current edition
56 if let X...true = 0 {} //~ ERROR only `char` and numeric types
57 //~^ ERROR `...` range patterns are deprecated
58 //~| WARN this is accepted in the current edition
59 if let .0...Y = 0 {} //~ ERROR mismatched types
60 //~^ ERROR float literals must have an integer part
61 //~| WARN this is accepted in the current edition
62 //~| ERROR `...` range patterns are deprecated
63 if let X... .0 = 0 {} //~ ERROR mismatched types
64 //~^ ERROR float literals must have an integer part
65 //~| ERROR `...` range patterns are deprecated
66 //~| WARN this is accepted in the current edition
73 //~^ ERROR only `char` and numeric types
75 //~^ ERROR float literals must have an integer part
76 //~| ERROR mismatched types
80 if let 0..= = 0 {} //~ ERROR inclusive range with no end
81 if let X..= = 0 {} //~ ERROR inclusive range with no end
82 if let true..= = 0 {} //~ ERROR inclusive range with no end
83 //~| ERROR only `char` and numeric types
84 if let .0..= = 0 {} //~ ERROR inclusive range with no end
85 //~^ ERROR float literals must have an integer part
86 //~| ERROR mismatched types
89 fn inclusive2_from() {
90 if let 0... = 0 {} //~ ERROR inclusive range with no end
91 if let X... = 0 {} //~ ERROR inclusive range with no end
92 if let true... = 0 {} //~ ERROR inclusive range with no end
93 //~| ERROR only `char` and numeric types
94 if let .0... = 0 {} //~ ERROR inclusive range with no end
95 //~^ ERROR float literals must have an integer part
96 //~| ERROR mismatched types
103 //~^ ERROR only `char` and numeric types
105 //~^ ERROR float literals must have an integer part
106 //~| ERROR mismatched types
112 if let ..=true = 0 {}
113 //~^ ERROR only `char` and numeric types
115 //~^ ERROR float literals must have an integer part
116 //~| ERROR mismatched types
121 //~^ ERROR range-to patterns with `...` are not allowed
123 //~^ ERROR range-to patterns with `...` are not allowed
124 if let ...true = 0 {}
125 //~^ ERROR range-to patterns with `...` are not allowed
126 //~| ERROR only `char` and numeric types
128 //~^ ERROR float literals must have an integer part
129 //~| ERROR range-to patterns with `...` are not allowed
130 //~| ERROR mismatched types
133 fn with_macro_expr_var() {
135 ($e1:expr, $e2:expr) => {
138 //~^ ERROR `...` range patterns are deprecated
139 //~| WARN this is accepted in the current edition
150 //~^ ERROR range-to patterns with `...` are not allowed
153 let $e...; //~ ERROR inclusive range with no end
154 let $e..=; //~ ERROR inclusive range with no end