]> git.lizzy.rs Git - rust.git/blob - src/test/ui/parser/recover-range-pats.rs
Auto merge of #102717 - beetrees:repr128-c-style-debuginfo, r=nagisa
[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 #![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 {}
42     //~^ ERROR `...` range patterns are deprecated
43     //~| WARN this is accepted in the current edition
44     if let 0...Y = 0 {}
45     //~^ ERROR `...` range patterns are deprecated
46     //~| WARN this is accepted in the current edition
47     if let X...3 = 0 {}
48     //~^ ERROR `...` range patterns are deprecated
49     //~| WARN this is accepted in the current edition
50     if let X...Y = 0 {}
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
67 }
68
69 fn exclusive_from() {
70     if let 0.. = 0 {}
71     if let X.. = 0 {}
72     if let true.. = 0 {}
73     //~^ ERROR only `char` and numeric types
74     if let .0.. = 0 {}
75     //~^ ERROR float literals must have an integer part
76     //~| ERROR mismatched types
77 }
78
79 fn inclusive_from() {
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
87 }
88
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
97 }
98
99 fn exclusive_to() {
100     if let ..0 = 0 {}
101     if let ..Y = 0 {}
102     if let ..true = 0 {}
103     //~^ ERROR only `char` and numeric types
104     if let .. .0 = 0 {}
105     //~^ ERROR float literals must have an integer part
106     //~| ERROR mismatched types
107 }
108
109 fn inclusive_to() {
110     if let ..=3 = 0 {}
111     if let ..=Y = 0 {}
112     if let ..=true = 0 {}
113     //~^ ERROR only `char` and numeric types
114     if let ..=.0 = 0 {}
115     //~^ ERROR float literals must have an integer part
116     //~| ERROR mismatched types
117 }
118
119 fn inclusive2_to() {
120     if let ...3 = 0 {}
121     //~^ ERROR range-to patterns with `...` are not allowed
122     if let ...Y = 0 {}
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
127     if let ....3 = 0 {}
128     //~^ ERROR float literals must have an integer part
129     //~| ERROR range-to patterns with `...` are not allowed
130     //~| ERROR mismatched types
131 }
132
133 fn with_macro_expr_var() {
134     macro_rules! mac2 {
135         ($e1:expr, $e2:expr) => {
136             let $e1..$e2;
137             let $e1...$e2;
138             //~^ ERROR `...` range patterns are deprecated
139             //~| WARN this is accepted in the current edition
140             let $e1..=$e2;
141         }
142     }
143
144     mac2!(0, 1);
145
146     macro_rules! mac {
147         ($e:expr) => {
148             let ..$e;
149             let ...$e;
150             //~^ ERROR range-to patterns with `...` are not allowed
151             let ..=$e;
152             let $e..;
153             let $e...; //~ ERROR inclusive range with no end
154             let $e..=; //~ ERROR inclusive range with no end
155         }
156     }
157
158     mac!(0);
159 }