Skip to content

Commit e18885e

Browse files
committed
Update ui and run-pass for ellipsis_inclusive_range_patterns lint
1 parent bf0da6c commit e18885e

10 files changed

+112
-31
lines changed

src/test/run-pass/associated-consts/associated-const-range-match-patterns.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// run-pass
22
#![allow(dead_code, unreachable_patterns)]
3+
#![allow(ellipsis_inclusive_range_patterns)]
34

45
struct Foo;
56

@@ -23,4 +24,17 @@ fn main() {
2324
<Foo as HasNum>::NUM ... <Foo>::NUM => true,
2425
_ => false,
2526
});
27+
28+
assert!(match 2 {
29+
Foo::NUM ..= 3 => true,
30+
_ => false,
31+
});
32+
assert!(match 0 {
33+
-1 ..= <Foo as HasNum>::NUM => true,
34+
_ => false,
35+
});
36+
assert!(match 1 {
37+
<Foo as HasNum>::NUM ..= <Foo>::NUM => true,
38+
_ => false,
39+
});
2640
}

src/test/run-pass/binding/pat-ranges.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// run-pass
22
// Parsing of range patterns
33

4+
#![allow(ellipsis_inclusive_range_patterns)]
5+
46
const NUM1: i32 = 10;
57

68
mod m {
@@ -11,4 +13,8 @@ fn main() {
1113
if let NUM1 ... m::NUM2 = 10 {} else { panic!() }
1214
if let ::NUM1 ... ::m::NUM2 = 11 {} else { panic!() }
1315
if let -13 ... -10 = 12 { panic!() } else {}
16+
17+
if let NUM1 ..= m::NUM2 = 10 {} else { panic!() }
18+
if let ::NUM1 ..= ::m::NUM2 = 11 {} else { panic!() }
19+
if let -13 ..= -10 = 12 { panic!() } else {}
1420
}

src/test/run-pass/inc-range-pat.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Test old and new syntax for inclusive range patterns.
22

3+
#![allow(ellipsis_inclusive_range_patterns)]
4+
35
fn main() {
46
assert!(match 42 { 0 ... 100 => true, _ => false });
57
assert!(match 42 { 0 ..= 100 => true, _ => false });

src/test/run-pass/issues/issue-15881-model-lexer-dotdotdot.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// run-pass
22
#![allow(illegal_floating_point_literal_pattern)] // FIXME #41620
3+
#![allow(ellipsis_inclusive_range_patterns)]
34

45
// regression test for the model lexer handling the DOTDOTDOT syntax (#15877)
56

src/test/run-pass/mir/mir_build_match_comparisons.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![allow(dead_code)]
33
fn test1(x: i8) -> i32 {
44
match x {
5-
1...10 => 0,
5+
1..=10 => 0,
66
_ => 1,
77
}
88
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
// compile-pass
22

3+
#![allow(ellipsis_inclusive_range_patterns)]
34
#![allow(unreachable_patterns)]
45
#![allow(unused_variables)]
56
#![warn(unused_parens)]
67

78
fn main() {
9+
match 1 {
10+
(_) => {} //~ WARNING: unnecessary parentheses around pattern
11+
(y) => {} //~ WARNING: unnecessary parentheses around pattern
12+
(ref r) => {} //~ WARNING: unnecessary parentheses around pattern
13+
(e @ 1...2) => {} //~ WARNING: unnecessary parentheses around outer pattern
14+
(1...2) => {} // Non ambiguous range pattern should not warn
15+
e @ (3...4) => {} // Non ambiguous range pattern should not warn
16+
}
17+
18+
match &1 {
19+
(e @ &(1...2)) => {} //~ WARNING: unnecessary parentheses around outer pattern
20+
&(_) => {} //~ WARNING: unnecessary parentheses around pattern
21+
e @ &(1...2) => {} // Ambiguous range pattern should not warn
22+
&(1...2) => {} // Ambiguous range pattern should not warn
23+
}
24+
25+
match &1 {
26+
e @ &(1...2) | e @ &(3...4) => {} // Complex ambiguous pattern should not warn
27+
&_ => {}
28+
}
29+
830
match 1 {
931
(_) => {} //~ WARNING: unnecessary parentheses around pattern
1032
(y) => {} //~ WARNING: unnecessary parentheses around pattern
@@ -15,14 +37,14 @@ fn main() {
1537
}
1638

1739
match &1 {
18-
(e @ &(1...2)) => {} //~ WARNING: unnecessary parentheses around outer pattern
40+
(e @ &(1..=2)) => {} //~ WARNING: unnecessary parentheses around outer pattern
1941
&(_) => {} //~ WARNING: unnecessary parentheses around pattern
20-
e @ &(1...2) => {} // Ambiguous range pattern should not warn
42+
e @ &(1..=2) => {} // Ambiguous range pattern should not warn
2143
&(1..=2) => {} // Ambiguous range pattern should not warn
2244
}
2345

2446
match &1 {
25-
e @ &(1...2) | e @ &(3..=4) => {} // Complex ambiguous pattern should not warn
47+
e @ &(1..=2) | e @ &(3..=4) => {} // Complex ambiguous pattern should not warn
2648
&_ => {}
2749
}
2850
}

src/test/ui/lint/issue-54538-unused-parens-lint.stderr

+44-8
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,77 @@
11
warning: unnecessary parentheses around pattern
2-
--> $DIR/issue-54538-unused-parens-lint.rs:9:9
2+
--> $DIR/issue-54538-unused-parens-lint.rs:10:9
33
|
44
LL | (_) => {}
55
| ^^^ help: remove these parentheses
66
|
77
note: lint level defined here
8-
--> $DIR/issue-54538-unused-parens-lint.rs:5:9
8+
--> $DIR/issue-54538-unused-parens-lint.rs:6:9
99
|
1010
LL | #![warn(unused_parens)]
1111
| ^^^^^^^^^^^^^
1212

1313
warning: unnecessary parentheses around pattern
14-
--> $DIR/issue-54538-unused-parens-lint.rs:10:9
14+
--> $DIR/issue-54538-unused-parens-lint.rs:11:9
1515
|
1616
LL | (y) => {}
1717
| ^^^ help: remove these parentheses
1818

1919
warning: unnecessary parentheses around pattern
20-
--> $DIR/issue-54538-unused-parens-lint.rs:11:9
20+
--> $DIR/issue-54538-unused-parens-lint.rs:12:9
2121
|
2222
LL | (ref r) => {}
2323
| ^^^^^^^ help: remove these parentheses
2424

2525
warning: unnecessary parentheses around pattern
26-
--> $DIR/issue-54538-unused-parens-lint.rs:12:9
26+
--> $DIR/issue-54538-unused-parens-lint.rs:13:9
2727
|
28-
LL | (e @ 1..=2) => {}
28+
LL | (e @ 1...2) => {}
2929
| ^^^^^^^^^^^ help: remove these parentheses
3030

3131
warning: unnecessary parentheses around pattern
32-
--> $DIR/issue-54538-unused-parens-lint.rs:18:9
32+
--> $DIR/issue-54538-unused-parens-lint.rs:19:9
3333
|
3434
LL | (e @ &(1...2)) => {}
3535
| ^^^^^^^^^^^^^^ help: remove these parentheses
3636

3737
warning: unnecessary parentheses around pattern
38-
--> $DIR/issue-54538-unused-parens-lint.rs:19:10
38+
--> $DIR/issue-54538-unused-parens-lint.rs:20:10
39+
|
40+
LL | &(_) => {}
41+
| ^^^ help: remove these parentheses
42+
43+
warning: unnecessary parentheses around pattern
44+
--> $DIR/issue-54538-unused-parens-lint.rs:31:9
45+
|
46+
LL | (_) => {}
47+
| ^^^ help: remove these parentheses
48+
49+
warning: unnecessary parentheses around pattern
50+
--> $DIR/issue-54538-unused-parens-lint.rs:32:9
51+
|
52+
LL | (y) => {}
53+
| ^^^ help: remove these parentheses
54+
55+
warning: unnecessary parentheses around pattern
56+
--> $DIR/issue-54538-unused-parens-lint.rs:33:9
57+
|
58+
LL | (ref r) => {}
59+
| ^^^^^^^ help: remove these parentheses
60+
61+
warning: unnecessary parentheses around pattern
62+
--> $DIR/issue-54538-unused-parens-lint.rs:34:9
63+
|
64+
LL | (e @ 1..=2) => {}
65+
| ^^^^^^^^^^^ help: remove these parentheses
66+
67+
warning: unnecessary parentheses around pattern
68+
--> $DIR/issue-54538-unused-parens-lint.rs:40:9
69+
|
70+
LL | (e @ &(1..=2)) => {}
71+
| ^^^^^^^^^^^^^^ help: remove these parentheses
72+
73+
warning: unnecessary parentheses around pattern
74+
--> $DIR/issue-54538-unused-parens-lint.rs:41:10
3975
|
4076
LL | &(_) => {}
4177
| ^^^ help: remove these parentheses

src/test/ui/match/match-range-fail-dominate.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,31 @@
88

99
fn main() {
1010
match 5 {
11-
1 ... 10 => { }
12-
5 ... 6 => { }
11+
1 ..= 10 => { }
12+
5 ..= 6 => { }
1313
_ => {}
1414
};
1515

1616
match 5 {
17-
3 ... 6 => { }
18-
4 ... 6 => { }
17+
3 ..= 6 => { }
18+
4 ..= 6 => { }
1919
_ => {}
2020
};
2121

2222
match 5 {
23-
4 ... 6 => { }
24-
4 ... 6 => { }
23+
4 ..= 6 => { }
24+
4 ..= 6 => { }
2525
_ => {}
2626
};
2727

2828
match 'c' {
29-
'A' ... 'z' => {}
30-
'a' ... 'z' => {}
29+
'A' ..= 'z' => {}
30+
'a' ..= 'z' => {}
3131
_ => {}
3232
};
3333

3434
match 1.0f64 {
35-
0.01f64 ... 6.5f64 => {}
35+
0.01f64 ..= 6.5f64 => {}
3636
0.02f64 => {}
3737
_ => {}
3838
};

src/test/ui/match/match-range-fail-dominate.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
error: unreachable pattern
22
--> $DIR/match-range-fail-dominate.rs:12:7
33
|
4-
LL | 5 ... 6 => { }
4+
LL | 5 ..= 6 => { }
55
| ^^^^^^^
66
|
77
note: lint level defined here
@@ -13,25 +13,25 @@ LL | #![deny(unreachable_patterns)]
1313
error: unreachable pattern
1414
--> $DIR/match-range-fail-dominate.rs:18:7
1515
|
16-
LL | 4 ... 6 => { }
16+
LL | 4 ..= 6 => { }
1717
| ^^^^^^^
1818

1919
error: unreachable pattern
2020
--> $DIR/match-range-fail-dominate.rs:24:7
2121
|
22-
LL | 4 ... 6 => { }
22+
LL | 4 ..= 6 => { }
2323
| ^^^^^^^
2424

2525
error: unreachable pattern
2626
--> $DIR/match-range-fail-dominate.rs:30:7
2727
|
28-
LL | 'a' ... 'z' => {}
28+
LL | 'a' ..= 'z' => {}
2929
| ^^^^^^^^^^^
3030

3131
warning: floating-point types cannot be used in patterns
3232
--> $DIR/match-range-fail-dominate.rs:35:7
3333
|
34-
LL | 0.01f64 ... 6.5f64 => {}
34+
LL | 0.01f64 ..= 6.5f64 => {}
3535
| ^^^^^^^
3636
|
3737
= note: #[warn(illegal_floating_point_literal_pattern)] on by default
@@ -41,7 +41,7 @@ LL | 0.01f64 ... 6.5f64 => {}
4141
warning: floating-point types cannot be used in patterns
4242
--> $DIR/match-range-fail-dominate.rs:35:19
4343
|
44-
LL | 0.01f64 ... 6.5f64 => {}
44+
LL | 0.01f64 ..= 6.5f64 => {}
4545
| ^^^^^^
4646
|
4747
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
@@ -65,7 +65,7 @@ LL | 0.02f64 => {}
6565
warning: floating-point types cannot be used in patterns
6666
--> $DIR/match-range-fail-dominate.rs:35:7
6767
|
68-
LL | 0.01f64 ... 6.5f64 => {}
68+
LL | 0.01f64 ..= 6.5f64 => {}
6969
| ^^^^^^^
7070
|
7171
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

src/test/ui/nll/issue-57960.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ impl Range for ThreeDigits {
2727

2828
fn digits(x: u8) -> u32 {
2929
match x {
30-
OneDigit::FIRST...OneDigit::LAST => 1,
31-
TwoDigits::FIRST...TwoDigits::LAST => 2,
32-
ThreeDigits::FIRST...ThreeDigits::LAST => 3,
30+
OneDigit::FIRST..=OneDigit::LAST => 1,
31+
TwoDigits::FIRST..=TwoDigits::LAST => 2,
32+
ThreeDigits::FIRST..=ThreeDigits::LAST => 3,
3333
_ => unreachable!(),
3434
}
3535
}

0 commit comments

Comments
 (0)