]>
git.proxmox.com Git - rustc.git/blob - 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.
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() {
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
62 //~^ ERROR only char and numeric types
64 //~^ ERROR float literals must have an integer part
65 //~| ERROR mismatched types
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
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
92 //~^ ERROR only char and numeric types
94 //~^ ERROR float literals must have an integer part
95 //~| ERROR mismatched types
101 if let ..=true = 0 {}
102 //~^ ERROR only char and numeric types
104 //~^ ERROR float literals must have an integer part
105 //~| ERROR mismatched types
110 //~^ ERROR range-to patterns with `...` are not allowed
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
117 //~^ ERROR float literals must have an integer part
118 //~| ERROR range-to patterns with `...` are not allowed
119 //~| ERROR mismatched types
122 fn with_macro_expr_var() {
124 ($e1
:expr
, $e2
:expr
) => {
127 //~^ ERROR `...` range patterns are deprecated
138 //~^ ERROR range-to patterns with `...` are not allowed
141 let $e
...; //~ ERROR inclusive range with no end
142 let $e
..=; //~ ERROR inclusive range with no end