blob: e07ea6221d7c95637e7b103756d16164c2a5a81b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
// Here we test all kinds of range patterns in terms of parsing / recovery.
// We want to ensure that:
// 1. Things parse as they should.
// 2. Or at least we have parser recovery if they don't.
#![feature(exclusive_range_pattern)]
#![feature(half_open_range_patterns)]
#![deny(ellipsis_inclusive_range_patterns)]
fn main() {}
const X: u8 = 0;
const Y: u8 = 3;
fn exclusive_from_to() {
if let 0..3 = 0 {} // OK.
if let 0..Y = 0 {} // OK.
if let X..3 = 0 {} // OK.
if let X..Y = 0 {} // OK.
if let true..Y = 0 {} //~ ERROR only char and numeric types
if let X..true = 0 {} //~ ERROR only char and numeric types
if let .0..Y = 0 {} //~ ERROR mismatched types
//~^ ERROR float literals must have an integer part
if let X.. .0 = 0 {} //~ ERROR mismatched types
//~^ ERROR float literals must have an integer part
}
fn inclusive_from_to() {
if let 0..=3 = 0 {} // OK.
if let 0..=Y = 0 {} // OK.
if let X..=3 = 0 {} // OK.
if let X..=Y = 0 {} // OK.
if let true..=Y = 0 {} //~ ERROR only char and numeric types
if let X..=true = 0 {} //~ ERROR only char and numeric types
if let .0..=Y = 0 {} //~ ERROR mismatched types
//~^ ERROR float literals must have an integer part
if let X..=.0 = 0 {} //~ ERROR mismatched types
//~^ ERROR float literals must have an integer part
}
fn inclusive2_from_to() {
if let 0...3 = 0 {} //~ ERROR `...` range patterns are deprecated
if let 0...Y = 0 {} //~ ERROR `...` range patterns are deprecated
if let X...3 = 0 {} //~ ERROR `...` range patterns are deprecated
if let X...Y = 0 {} //~ ERROR `...` range patterns are deprecated
if let true...Y = 0 {} //~ ERROR only char and numeric types
//~^ ERROR `...` range patterns are deprecated
if let X...true = 0 {} //~ ERROR only char and numeric types
//~^ ERROR `...` range patterns are deprecated
if let .0...Y = 0 {} //~ ERROR mismatched types
//~^ ERROR float literals must have an integer part
//~| ERROR `...` range patterns are deprecated
if let X... .0 = 0 {} //~ ERROR mismatched types
//~^ ERROR float literals must have an integer part
//~| ERROR `...` range patterns are deprecated
}
fn exclusive_from() {
if let 0.. = 0 {}
if let X.. = 0 {}
if let true.. = 0 {}
//~^ ERROR only char and numeric types
if let .0.. = 0 {}
//~^ ERROR float literals must have an integer part
//~| ERROR mismatched types
}
fn inclusive_from() {
if let 0..= = 0 {} //~ ERROR inclusive range with no end
if let X..= = 0 {} //~ ERROR inclusive range with no end
if let true..= = 0 {} //~ ERROR inclusive range with no end
//~| ERROR only char and numeric types
if let .0..= = 0 {} //~ ERROR inclusive range with no end
//~^ ERROR float literals must have an integer part
//~| ERROR mismatched types
}
fn inclusive2_from() {
if let 0... = 0 {} //~ ERROR inclusive range with no end
if let X... = 0 {} //~ ERROR inclusive range with no end
if let true... = 0 {} //~ ERROR inclusive range with no end
//~| ERROR only char and numeric types
if let .0... = 0 {} //~ ERROR inclusive range with no end
//~^ ERROR float literals must have an integer part
//~| ERROR mismatched types
}
fn exclusive_to() {
if let ..0 = 0 {}
if let ..Y = 0 {}
if let ..true = 0 {}
//~^ ERROR only char and numeric types
if let .. .0 = 0 {}
//~^ ERROR float literals must have an integer part
//~| ERROR mismatched types
}
fn inclusive_to() {
if let ..=3 = 0 {}
if let ..=Y = 0 {}
if let ..=true = 0 {}
//~^ ERROR only char and numeric types
if let ..=.0 = 0 {}
//~^ ERROR float literals must have an integer part
//~| ERROR mismatched types
}
fn inclusive2_to() {
if let ...3 = 0 {}
//~^ ERROR range-to patterns with `...` are not allowed
if let ...Y = 0 {}
//~^ ERROR range-to patterns with `...` are not allowed
if let ...true = 0 {}
//~^ ERROR range-to patterns with `...` are not allowed
//~| ERROR only char and numeric types
if let ....3 = 0 {}
//~^ ERROR float literals must have an integer part
//~| ERROR range-to patterns with `...` are not allowed
//~| ERROR mismatched types
}
fn with_macro_expr_var() {
macro_rules! mac2 {
($e1:expr, $e2:expr) => {
let $e1..$e2;
let $e1...$e2;
//~^ ERROR `...` range patterns are deprecated
let $e1..=$e2;
}
}
mac2!(0, 1);
macro_rules! mac {
($e:expr) => {
let ..$e;
let ...$e;
//~^ ERROR range-to patterns with `...` are not allowed
let ..=$e;
let $e..;
let $e...; //~ ERROR inclusive range with no end
let $e..=; //~ ERROR inclusive range with no end
}
}
mac!(0);
}
|