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 #![feature(half_open_range_patterns)]
8 #![deny(ellipsis_inclusive_range_patterns)]
15 fn exclusive_from_to() {
16 if let 0..3 = 0 {} // OK.
17 if let 0..Y = 0 {} // OK.
18 if let X..3 = 0 {} // OK.
19 if let X..Y = 0 {} // OK.
20 if let true..Y = 0 {} //~ ERROR only `char` and numeric types
21 if let X..true = 0 {} //~ ERROR only `char` and numeric types
22 if let .0..Y = 0 {} //~ ERROR mismatched types
23 //~^ ERROR float literals must have an integer part
24 if let X.. .0 = 0 {} //~ ERROR mismatched types
25 //~^ ERROR float literals must have an integer part
28 fn inclusive_from_to() {
29 if let 0..=3 = 0 {} // OK.
30 if let 0..=Y = 0 {} // OK.
31 if let X..=3 = 0 {} // OK.
32 if let X..=Y = 0 {} // OK.
33 if let true..=Y = 0 {} //~ ERROR only `char` and numeric types
34 if let X..=true = 0 {} //~ ERROR only `char` and numeric types
35 if let .0..=Y = 0 {} //~ ERROR mismatched types
36 //~^ ERROR float literals must have an integer part
37 if let X..=.0 = 0 {} //~ ERROR mismatched types
38 //~^ ERROR float literals must have an integer part
41 fn inclusive2_from_to() {
43 //~^ ERROR `...` range patterns are deprecated
44 //~| WARN this is accepted in the current edition
46 //~^ ERROR `...` range patterns are deprecated
47 //~| WARN this is accepted in the current edition
49 //~^ ERROR `...` range patterns are deprecated
50 //~| WARN this is accepted in the current edition
52 //~^ ERROR `...` range patterns are deprecated
53 //~| WARN this is accepted in the current edition
54 if let true...Y = 0 {} //~ ERROR only `char` and numeric types
55 //~^ ERROR `...` range patterns are deprecated
56 //~| WARN this is accepted in the current edition
57 if let X...true = 0 {} //~ ERROR only `char` and numeric types
58 //~^ ERROR `...` range patterns are deprecated
59 //~| WARN this is accepted in the current edition
60 if let .0...Y = 0 {} //~ ERROR mismatched types
61 //~^ ERROR float literals must have an integer part
62 //~| WARN this is accepted in the current edition
63 //~| ERROR `...` range patterns are deprecated
64 if let X... .0 = 0 {} //~ ERROR mismatched types
65 //~^ ERROR float literals must have an integer part
66 //~| ERROR `...` range patterns are deprecated
67 //~| WARN this is accepted in the current edition
74 //~^ ERROR only `char` and numeric types
76 //~^ ERROR float literals must have an integer part
77 //~| ERROR mismatched types
81 if let 0..= = 0 {} //~ ERROR inclusive range with no end
82 if let X..= = 0 {} //~ ERROR inclusive range with no end
83 if let true..= = 0 {} //~ ERROR inclusive range with no end
84 //~| ERROR only `char` and numeric types
85 if let .0..= = 0 {} //~ ERROR inclusive range with no end
86 //~^ ERROR float literals must have an integer part
87 //~| ERROR mismatched types
90 fn inclusive2_from() {
91 if let 0... = 0 {} //~ ERROR inclusive range with no end
92 if let X... = 0 {} //~ ERROR inclusive range with no end
93 if let true... = 0 {} //~ ERROR inclusive range with no end
94 //~| ERROR only `char` and numeric types
95 if let .0... = 0 {} //~ ERROR inclusive range with no end
96 //~^ ERROR float literals must have an integer part
97 //~| ERROR mismatched types
104 //~^ ERROR only `char` and numeric types
106 //~^ ERROR float literals must have an integer part
107 //~| ERROR mismatched types
113 if let ..=true = 0 {}
114 //~^ ERROR only `char` and numeric types
116 //~^ ERROR float literals must have an integer part
117 //~| ERROR mismatched types
122 //~^ ERROR range-to patterns with `...` are not allowed
124 //~^ ERROR range-to patterns with `...` are not allowed
125 if let ...true = 0 {}
126 //~^ ERROR range-to patterns with `...` are not allowed
127 //~| ERROR only `char` and numeric types
129 //~^ ERROR float literals must have an integer part
130 //~| ERROR range-to patterns with `...` are not allowed
131 //~| ERROR mismatched types
134 fn with_macro_expr_var() {
136 ($e1:expr, $e2:expr) => {
139 //~^ ERROR `...` range patterns are deprecated
140 //~| WARN this is accepted in the current edition
151 //~^ ERROR range-to patterns with `...` are not allowed
154 let $e...; //~ ERROR inclusive range with no end
155 let $e..=; //~ ERROR inclusive range with no end