]> git.lizzy.rs Git - rust.git/blob - src/test/ui/parser/recover-range-pats.rs
Point (again) to more expressions with their type, even if not fully resolved
[rust.git] / src / test / ui / parser / recover-range-pats.rs
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 #![feature(half_open_range_patterns)]
8 #![deny(ellipsis_inclusive_range_patterns)]
9
10 fn main() {}
11
12 const X: u8 = 0;
13 const Y: u8 = 3;
14
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
26 }
27
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
39 }
40
41 fn inclusive2_from_to() {
42     if let 0...3 = 0 {}
43     //~^ ERROR `...` range patterns are deprecated
44     //~| WARN this is accepted in the current edition
45     if let 0...Y = 0 {}
46     //~^ ERROR `...` range patterns are deprecated
47     //~| WARN this is accepted in the current edition
48     if let X...3 = 0 {}
49     //~^ ERROR `...` range patterns are deprecated
50     //~| WARN this is accepted in the current edition
51     if let X...Y = 0 {}
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
68 }
69
70 fn exclusive_from() {
71     if let 0.. = 0 {}
72     if let X.. = 0 {}
73     if let true.. = 0 {}
74     //~^ ERROR only `char` and numeric types
75     if let .0.. = 0 {}
76     //~^ ERROR float literals must have an integer part
77     //~| ERROR mismatched types
78 }
79
80 fn inclusive_from() {
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
88 }
89
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
98 }
99
100 fn exclusive_to() {
101     if let ..0 = 0 {}
102     if let ..Y = 0 {}
103     if let ..true = 0 {}
104     //~^ ERROR only `char` and numeric types
105     if let .. .0 = 0 {}
106     //~^ ERROR float literals must have an integer part
107     //~| ERROR mismatched types
108 }
109
110 fn inclusive_to() {
111     if let ..=3 = 0 {}
112     if let ..=Y = 0 {}
113     if let ..=true = 0 {}
114     //~^ ERROR only `char` and numeric types
115     if let ..=.0 = 0 {}
116     //~^ ERROR float literals must have an integer part
117     //~| ERROR mismatched types
118 }
119
120 fn inclusive2_to() {
121     if let ...3 = 0 {}
122     //~^ ERROR range-to patterns with `...` are not allowed
123     if let ...Y = 0 {}
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
128     if let ....3 = 0 {}
129     //~^ ERROR float literals must have an integer part
130     //~| ERROR range-to patterns with `...` are not allowed
131     //~| ERROR mismatched types
132 }
133
134 fn with_macro_expr_var() {
135     macro_rules! mac2 {
136         ($e1:expr, $e2:expr) => {
137             let $e1..$e2;
138             let $e1...$e2;
139             //~^ ERROR `...` range patterns are deprecated
140             //~| WARN this is accepted in the current edition
141             let $e1..=$e2;
142         }
143     }
144
145     mac2!(0, 1);
146
147     macro_rules! mac {
148         ($e:expr) => {
149             let ..$e;
150             let ...$e;
151             //~^ ERROR range-to patterns with `...` are not allowed
152             let ..=$e;
153             let $e..;
154             let $e...; //~ ERROR inclusive range with no end
155             let $e..=; //~ ERROR inclusive range with no end
156         }
157     }
158
159     mac!(0);
160 }