]> git.lizzy.rs Git - rust.git/blob - src/test/ui/parser/recover-range-pats.rs
Auto merge of #82576 - gilescope:to_string, r=Amanieu
[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 {} //~ ERROR `...` range patterns are deprecated
43     if let 0...Y = 0 {} //~ ERROR `...` range patterns are deprecated
44     if let X...3 = 0 {} //~ ERROR `...` range patterns are deprecated
45     if let X...Y = 0 {} //~ ERROR `...` range patterns are deprecated
46     if let true...Y = 0 {} //~ ERROR only `char` and numeric types
47     //~^ ERROR `...` range patterns are deprecated
48     if let X...true = 0 {} //~ ERROR only `char` and numeric types
49     //~^ ERROR `...` range patterns are deprecated
50     if let .0...Y = 0 {} //~ ERROR mismatched types
51     //~^ ERROR float literals must have an integer part
52     //~| ERROR `...` range patterns are deprecated
53     if let X... .0 = 0 {} //~ ERROR mismatched types
54     //~^ ERROR float literals must have an integer part
55     //~| ERROR `...` range patterns are deprecated
56 }
57
58 fn exclusive_from() {
59     if let 0.. = 0 {}
60     if let X.. = 0 {}
61     if let true.. = 0 {}
62     //~^ ERROR only `char` and numeric types
63     if let .0.. = 0 {}
64     //~^ ERROR float literals must have an integer part
65     //~| ERROR mismatched types
66 }
67
68 fn inclusive_from() {
69     if let 0..= = 0 {} //~ ERROR inclusive range with no end
70     if let X..= = 0 {} //~ ERROR inclusive range with no end
71     if let true..= = 0 {} //~ ERROR inclusive range with no end
72     //~| ERROR only `char` and numeric types
73     if let .0..= = 0 {} //~ ERROR inclusive range with no end
74     //~^ ERROR float literals must have an integer part
75     //~| ERROR mismatched types
76 }
77
78 fn inclusive2_from() {
79     if let 0... = 0 {} //~ ERROR inclusive range with no end
80     if let X... = 0 {} //~ ERROR inclusive range with no end
81     if let true... = 0 {} //~ ERROR inclusive range with no end
82     //~| ERROR only `char` and numeric types
83     if let .0... = 0 {} //~ ERROR inclusive range with no end
84     //~^ ERROR float literals must have an integer part
85     //~| ERROR mismatched types
86 }
87
88 fn exclusive_to() {
89     if let ..0 = 0 {}
90     if let ..Y = 0 {}
91     if let ..true = 0 {}
92     //~^ ERROR only `char` and numeric types
93     if let .. .0 = 0 {}
94     //~^ ERROR float literals must have an integer part
95     //~| ERROR mismatched types
96 }
97
98 fn inclusive_to() {
99     if let ..=3 = 0 {}
100     if let ..=Y = 0 {}
101     if let ..=true = 0 {}
102     //~^ ERROR only `char` and numeric types
103     if let ..=.0 = 0 {}
104     //~^ ERROR float literals must have an integer part
105     //~| ERROR mismatched types
106 }
107
108 fn inclusive2_to() {
109     if let ...3 = 0 {}
110     //~^ ERROR range-to patterns with `...` are not allowed
111     if let ...Y = 0 {}
112     //~^ ERROR range-to patterns with `...` are not allowed
113     if let ...true = 0 {}
114     //~^ ERROR range-to patterns with `...` are not allowed
115     //~| ERROR only `char` and numeric types
116     if let ....3 = 0 {}
117     //~^ ERROR float literals must have an integer part
118     //~| ERROR range-to patterns with `...` are not allowed
119     //~| ERROR mismatched types
120 }
121
122 fn with_macro_expr_var() {
123     macro_rules! mac2 {
124         ($e1:expr, $e2:expr) => {
125             let $e1..$e2;
126             let $e1...$e2;
127             //~^ ERROR `...` range patterns are deprecated
128             let $e1..=$e2;
129         }
130     }
131
132     mac2!(0, 1);
133
134     macro_rules! mac {
135         ($e:expr) => {
136             let ..$e;
137             let ...$e;
138             //~^ ERROR range-to patterns with `...` are not allowed
139             let ..=$e;
140             let $e..;
141             let $e...; //~ ERROR inclusive range with no end
142             let $e..=; //~ ERROR inclusive range with no end
143         }
144     }
145
146     mac!(0);
147 }