Skip to content

Commit 2bc180e

Browse files
committed
Auto merge of #79278 - mark-i-m:stabilize-or-pattern, r=nikomatsakis
Stabilize or_patterns (RFC 2535, 2530, 2175) closes #54883 This PR stabilizes the or_patterns feature in Rust 1.53. This is blocked on the following (in order): - [x] The crater run in rust-lang/rust#78935 (comment) - [x] The resolution of the unresolved questions and a second crater run (rust-lang/rust#78935 (comment)) - It looks like we will need to pursue some sort of edition-based transition for `:pat`. - [x] Nomination and discussion by T-lang - [x] Implement new behavior for `:pat` based on consensus (rust-lang/rust#80100). - [ ] An FCP on stabilization EDIT: Stabilization report is in rust-lang/rust#79278 (comment)
2 parents 731c98b + d2f0b27 commit 2bc180e

13 files changed

+33
-50
lines changed

clippy_lints/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#![feature(drain_filter)]
66
#![feature(in_band_lifetimes)]
77
#![feature(once_cell)]
8-
#![feature(or_patterns)]
8+
#![cfg_attr(bootstrap, feature(or_patterns))]
99
#![feature(rustc_private)]
1010
#![feature(stmt_expr_attributes)]
1111
#![feature(control_flow_enum)]

clippy_lints/src/unnested_or_patterns.rs

-5
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ impl EarlyLintPass for UnnestedOrPatterns {
7272
}
7373

7474
fn lint_unnested_or_patterns(cx: &EarlyContext<'_>, pat: &Pat) {
75-
if !cx.sess.features_untracked().or_patterns {
76-
// Do not suggest nesting the patterns if the feature `or_patterns` is not enabled.
77-
return;
78-
}
79-
8075
if let Ident(.., None) | Lit(_) | Wild | Path(..) | Range(..) | Rest | MacCall(_) = pat.kind {
8176
// This is a leaf pattern, so cloning is unprofitable.
8277
return;

clippy_utils/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(box_patterns)]
22
#![feature(in_band_lifetimes)]
3-
#![feature(or_patterns)]
3+
#![cfg_attr(bootstrap, feature(or_patterns))]
44
#![feature(rustc_private)]
55
#![recursion_limit = "512"]
66
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc, clippy::must_use_candidate)]

tests/ui/unnested_or_patterns.fixed

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// run-rustfix
22

3-
#![feature(or_patterns)]
43
#![feature(box_patterns)]
54
#![warn(clippy::unnested_or_patterns)]
65
#![allow(clippy::cognitive_complexity, clippy::match_ref_pats, clippy::upper_case_acronyms)]

tests/ui/unnested_or_patterns.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// run-rustfix
22

3-
#![feature(or_patterns)]
43
#![feature(box_patterns)]
54
#![warn(clippy::unnested_or_patterns)]
65
#![allow(clippy::cognitive_complexity, clippy::match_ref_pats, clippy::upper_case_acronyms)]

tests/ui/unnested_or_patterns.stderr

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unnested or-patterns
2-
--> $DIR/unnested_or_patterns.rs:10:12
2+
--> $DIR/unnested_or_patterns.rs:9:12
33
|
44
LL | if let box 0 | box 2 = Box::new(0) {}
55
| ^^^^^^^^^^^^^
@@ -11,7 +11,7 @@ LL | if let box (0 | 2) = Box::new(0) {}
1111
| ^^^^^^^^^^^
1212

1313
error: unnested or-patterns
14-
--> $DIR/unnested_or_patterns.rs:11:12
14+
--> $DIR/unnested_or_patterns.rs:10:12
1515
|
1616
LL | if let box ((0 | 1)) | box (2 | 3) | box 4 = Box::new(0) {}
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -22,7 +22,7 @@ LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {}
2222
| ^^^^^^^^^^^^^^^^^^^^^^^
2323

2424
error: unnested or-patterns
25-
--> $DIR/unnested_or_patterns.rs:13:12
25+
--> $DIR/unnested_or_patterns.rs:12:12
2626
|
2727
LL | if let &0 | C0 | &2 = &0 {}
2828
| ^^^^^^^^^^^^
@@ -33,7 +33,7 @@ LL | if let &(0 | 2) | C0 = &0 {}
3333
| ^^^^^^^^^^^^^
3434

3535
error: unnested or-patterns
36-
--> $DIR/unnested_or_patterns.rs:14:12
36+
--> $DIR/unnested_or_patterns.rs:13:12
3737
|
3838
LL | if let &mut 0 | &mut 2 = &mut 0 {}
3939
| ^^^^^^^^^^^^^^^
@@ -44,7 +44,7 @@ LL | if let &mut (0 | 2) = &mut 0 {}
4444
| ^^^^^^^^^^^^
4545

4646
error: unnested or-patterns
47-
--> $DIR/unnested_or_patterns.rs:15:12
47+
--> $DIR/unnested_or_patterns.rs:14:12
4848
|
4949
LL | if let x @ 0 | x @ 2 = 0 {}
5050
| ^^^^^^^^^^^^^
@@ -55,7 +55,7 @@ LL | if let x @ (0 | 2) = 0 {}
5555
| ^^^^^^^^^^^
5656

5757
error: unnested or-patterns
58-
--> $DIR/unnested_or_patterns.rs:16:12
58+
--> $DIR/unnested_or_patterns.rs:15:12
5959
|
6060
LL | if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {}
6161
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -66,7 +66,7 @@ LL | if let (0, 1 | 2 | 3) = (0, 0) {}
6666
| ^^^^^^^^^^^^^^
6767

6868
error: unnested or-patterns
69-
--> $DIR/unnested_or_patterns.rs:17:12
69+
--> $DIR/unnested_or_patterns.rs:16:12
7070
|
7171
LL | if let (1, 0) | (2, 0) | (3, 0) = (0, 0) {}
7272
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -77,7 +77,7 @@ LL | if let (1 | 2 | 3, 0) = (0, 0) {}
7777
| ^^^^^^^^^^^^^^
7878

7979
error: unnested or-patterns
80-
--> $DIR/unnested_or_patterns.rs:18:12
80+
--> $DIR/unnested_or_patterns.rs:17:12
8181
|
8282
LL | if let (x, ..) | (x, 1) | (x, 2) = (0, 1) {}
8383
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -88,7 +88,7 @@ LL | if let (x, ..) | (x, 1 | 2) = (0, 1) {}
8888
| ^^^^^^^^^^^^^^^^^^^^
8989

9090
error: unnested or-patterns
91-
--> $DIR/unnested_or_patterns.rs:19:12
91+
--> $DIR/unnested_or_patterns.rs:18:12
9292
|
9393
LL | if let [0] | [1] = [0] {}
9494
| ^^^^^^^^^
@@ -99,7 +99,7 @@ LL | if let [0 | 1] = [0] {}
9999
| ^^^^^^^
100100

101101
error: unnested or-patterns
102-
--> $DIR/unnested_or_patterns.rs:20:12
102+
--> $DIR/unnested_or_patterns.rs:19:12
103103
|
104104
LL | if let [x, 0] | [x, 1] = [0, 1] {}
105105
| ^^^^^^^^^^^^^^^
@@ -110,7 +110,7 @@ LL | if let [x, 0 | 1] = [0, 1] {}
110110
| ^^^^^^^^^^
111111

112112
error: unnested or-patterns
113-
--> $DIR/unnested_or_patterns.rs:21:12
113+
--> $DIR/unnested_or_patterns.rs:20:12
114114
|
115115
LL | if let [x, 0] | [x, 1] | [x, 2] = [0, 1] {}
116116
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -121,7 +121,7 @@ LL | if let [x, 0 | 1 | 2] = [0, 1] {}
121121
| ^^^^^^^^^^^^^^
122122

123123
error: unnested or-patterns
124-
--> $DIR/unnested_or_patterns.rs:22:12
124+
--> $DIR/unnested_or_patterns.rs:21:12
125125
|
126126
LL | if let [x, ..] | [x, 1] | [x, 2] = [0, 1] {}
127127
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -132,7 +132,7 @@ LL | if let [x, ..] | [x, 1 | 2] = [0, 1] {}
132132
| ^^^^^^^^^^^^^^^^^^^^
133133

134134
error: unnested or-patterns
135-
--> $DIR/unnested_or_patterns.rs:24:12
135+
--> $DIR/unnested_or_patterns.rs:23:12
136136
|
137137
LL | if let TS(0, x) | TS(1, x) = TS(0, 0) {}
138138
| ^^^^^^^^^^^^^^^^^^^
@@ -143,7 +143,7 @@ LL | if let TS(0 | 1, x) = TS(0, 0) {}
143143
| ^^^^^^^^^^^^
144144

145145
error: unnested or-patterns
146-
--> $DIR/unnested_or_patterns.rs:25:12
146+
--> $DIR/unnested_or_patterns.rs:24:12
147147
|
148148
LL | if let TS(1, 0) | TS(2, 0) | TS(3, 0) = TS(0, 0) {}
149149
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -154,7 +154,7 @@ LL | if let TS(1 | 2 | 3, 0) = TS(0, 0) {}
154154
| ^^^^^^^^^^^^^^^^
155155

156156
error: unnested or-patterns
157-
--> $DIR/unnested_or_patterns.rs:26:12
157+
--> $DIR/unnested_or_patterns.rs:25:12
158158
|
159159
LL | if let TS(x, ..) | TS(x, 1) | TS(x, 2) = TS(0, 0) {}
160160
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -165,7 +165,7 @@ LL | if let TS(x, ..) | TS(x, 1 | 2) = TS(0, 0) {}
165165
| ^^^^^^^^^^^^^^^^^^^^^^^^
166166

167167
error: unnested or-patterns
168-
--> $DIR/unnested_or_patterns.rs:31:12
168+
--> $DIR/unnested_or_patterns.rs:30:12
169169
|
170170
LL | if let S { x: 0, y } | S { y, x: 1 } = (S { x: 0, y: 1 }) {}
171171
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/ui/unnested_or_patterns2.fixed

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// run-rustfix
22

3-
#![feature(or_patterns)]
43
#![feature(box_patterns)]
54
#![warn(clippy::unnested_or_patterns)]
65
#![allow(clippy::cognitive_complexity, clippy::match_ref_pats)]

tests/ui/unnested_or_patterns2.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// run-rustfix
22

3-
#![feature(or_patterns)]
43
#![feature(box_patterns)]
54
#![warn(clippy::unnested_or_patterns)]
65
#![allow(clippy::cognitive_complexity, clippy::match_ref_pats)]

tests/ui/unnested_or_patterns2.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unnested or-patterns
2-
--> $DIR/unnested_or_patterns2.rs:10:12
2+
--> $DIR/unnested_or_patterns2.rs:9:12
33
|
44
LL | if let Some(Some(0)) | Some(Some(1)) = None {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -11,7 +11,7 @@ LL | if let Some(Some(0 | 1)) = None {}
1111
| ^^^^^^^^^^^^^^^^^
1212

1313
error: unnested or-patterns
14-
--> $DIR/unnested_or_patterns2.rs:11:12
14+
--> $DIR/unnested_or_patterns2.rs:10:12
1515
|
1616
LL | if let Some(Some(0)) | Some(Some(1) | Some(2)) = None {}
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -22,7 +22,7 @@ LL | if let Some(Some(0 | 1 | 2)) = None {}
2222
| ^^^^^^^^^^^^^^^^^^^^^
2323

2424
error: unnested or-patterns
25-
--> $DIR/unnested_or_patterns2.rs:12:12
25+
--> $DIR/unnested_or_patterns2.rs:11:12
2626
|
2727
LL | if let Some(Some(0 | 1) | Some(2)) | Some(Some(3) | Some(4)) = None {}
2828
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -33,7 +33,7 @@ LL | if let Some(Some(0 | 1 | 2 | 3 | 4)) = None {}
3333
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3434

3535
error: unnested or-patterns
36-
--> $DIR/unnested_or_patterns2.rs:13:12
36+
--> $DIR/unnested_or_patterns2.rs:12:12
3737
|
3838
LL | if let Some(Some(0) | Some(1 | 2)) = None {}
3939
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -44,7 +44,7 @@ LL | if let Some(Some(0 | 1 | 2)) = None {}
4444
| ^^^^^^^^^^^^^^^^^^^^^
4545

4646
error: unnested or-patterns
47-
--> $DIR/unnested_or_patterns2.rs:14:12
47+
--> $DIR/unnested_or_patterns2.rs:13:12
4848
|
4949
LL | if let ((0,),) | ((1,) | (2,),) = ((0,),) {}
5050
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -55,7 +55,7 @@ LL | if let ((0 | 1 | 2,),) = ((0,),) {}
5555
| ^^^^^^^^^^^^^^^
5656

5757
error: unnested or-patterns
58-
--> $DIR/unnested_or_patterns2.rs:15:12
58+
--> $DIR/unnested_or_patterns2.rs:14:12
5959
|
6060
LL | if let 0 | (1 | 2) = 0 {}
6161
| ^^^^^^^^^^^
@@ -66,7 +66,7 @@ LL | if let 0 | 1 | 2 = 0 {}
6666
| ^^^^^^^^^
6767

6868
error: unnested or-patterns
69-
--> $DIR/unnested_or_patterns2.rs:16:12
69+
--> $DIR/unnested_or_patterns2.rs:15:12
7070
|
7171
LL | if let box (0 | 1) | (box 2 | box (3 | 4)) = Box::new(0) {}
7272
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -77,7 +77,7 @@ LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {}
7777
| ^^^^^^^^^^^^^^^^^^^^^^^
7878

7979
error: unnested or-patterns
80-
--> $DIR/unnested_or_patterns2.rs:17:12
80+
--> $DIR/unnested_or_patterns2.rs:16:12
8181
|
8282
LL | if let box box 0 | box (box 2 | box 4) = Box::new(Box::new(0)) {}
8383
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/ui/unnested_or_patterns3.rs

-6
This file was deleted.

tests/ui/while_let_on_iterator.fixed

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#![warn(clippy::while_let_on_iterator)]
44
#![allow(clippy::never_loop, unreachable_code, unused_mut)]
5-
#![feature(or_patterns)]
65

76
fn base() {
87
let mut iter = 1..20;

tests/ui/while_let_on_iterator.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#![warn(clippy::while_let_on_iterator)]
44
#![allow(clippy::never_loop, unreachable_code, unused_mut)]
5-
#![feature(or_patterns)]
65

76
fn base() {
87
let mut iter = 1..20;

tests/ui/while_let_on_iterator.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
error: this loop could be written as a `for` loop
2-
--> $DIR/while_let_on_iterator.rs:9:5
2+
--> $DIR/while_let_on_iterator.rs:8:5
33
|
44
LL | while let Option::Some(x) = iter.next() {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in iter`
66
|
77
= note: `-D clippy::while-let-on-iterator` implied by `-D warnings`
88

99
error: this loop could be written as a `for` loop
10-
--> $DIR/while_let_on_iterator.rs:14:5
10+
--> $DIR/while_let_on_iterator.rs:13:5
1111
|
1212
LL | while let Some(x) = iter.next() {
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in iter`
1414

1515
error: this loop could be written as a `for` loop
16-
--> $DIR/while_let_on_iterator.rs:19:5
16+
--> $DIR/while_let_on_iterator.rs:18:5
1717
|
1818
LL | while let Some(_) = iter.next() {}
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in iter`
2020

2121
error: this loop could be written as a `for` loop
22-
--> $DIR/while_let_on_iterator.rs:102:9
22+
--> $DIR/while_let_on_iterator.rs:101:9
2323
|
2424
LL | while let Some([..]) = it.next() {}
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for [..] in it`
2626

2727
error: this loop could be written as a `for` loop
28-
--> $DIR/while_let_on_iterator.rs:109:9
28+
--> $DIR/while_let_on_iterator.rs:108:9
2929
|
3030
LL | while let Some([_x]) = it.next() {}
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for [_x] in it`
3232

3333
error: this loop could be written as a `for` loop
34-
--> $DIR/while_let_on_iterator.rs:122:9
34+
--> $DIR/while_let_on_iterator.rs:121:9
3535
|
3636
LL | while let Some(x @ [_]) = it.next() {
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x @ [_] in it`
3838

3939
error: this loop could be written as a `for` loop
40-
--> $DIR/while_let_on_iterator.rs:154:9
40+
--> $DIR/while_let_on_iterator.rs:153:9
4141
|
4242
LL | while let Some(_) = y.next() {
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in y`

0 commit comments

Comments
 (0)