Skip to content

Commit

Permalink
Auto merge of #79278 - mark-i-m:stabilize-or-pattern, r=nikomatsakis
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
bors committed Mar 22, 2021
2 parents 731c98b + d2f0b27 commit 2bc180e
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 50 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![feature(drain_filter)]
#![feature(in_band_lifetimes)]
#![feature(once_cell)]
#![feature(or_patterns)]
#![cfg_attr(bootstrap, feature(or_patterns))]
#![feature(rustc_private)]
#![feature(stmt_expr_attributes)]
#![feature(control_flow_enum)]
Expand Down
5 changes: 0 additions & 5 deletions clippy_lints/src/unnested_or_patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ impl EarlyLintPass for UnnestedOrPatterns {
}

fn lint_unnested_or_patterns(cx: &EarlyContext<'_>, pat: &Pat) {
if !cx.sess.features_untracked().or_patterns {
// Do not suggest nesting the patterns if the feature `or_patterns` is not enabled.
return;
}

if let Ident(.., None) | Lit(_) | Wild | Path(..) | Range(..) | Rest | MacCall(_) = pat.kind {
// This is a leaf pattern, so cloning is unprofitable.
return;
Expand Down
2 changes: 1 addition & 1 deletion clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(box_patterns)]
#![feature(in_band_lifetimes)]
#![feature(or_patterns)]
#![cfg_attr(bootstrap, feature(or_patterns))]
#![feature(rustc_private)]
#![recursion_limit = "512"]
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc, clippy::must_use_candidate)]
Expand Down
1 change: 0 additions & 1 deletion tests/ui/unnested_or_patterns.fixed
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// run-rustfix

#![feature(or_patterns)]
#![feature(box_patterns)]
#![warn(clippy::unnested_or_patterns)]
#![allow(clippy::cognitive_complexity, clippy::match_ref_pats, clippy::upper_case_acronyms)]
Expand Down
1 change: 0 additions & 1 deletion tests/ui/unnested_or_patterns.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// run-rustfix

#![feature(or_patterns)]
#![feature(box_patterns)]
#![warn(clippy::unnested_or_patterns)]
#![allow(clippy::cognitive_complexity, clippy::match_ref_pats, clippy::upper_case_acronyms)]
Expand Down
32 changes: 16 additions & 16 deletions tests/ui/unnested_or_patterns.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:10:12
--> $DIR/unnested_or_patterns.rs:9:12
|
LL | if let box 0 | box 2 = Box::new(0) {}
| ^^^^^^^^^^^^^
Expand All @@ -11,7 +11,7 @@ LL | if let box (0 | 2) = Box::new(0) {}
| ^^^^^^^^^^^

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

error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:13:12
--> $DIR/unnested_or_patterns.rs:12:12
|
LL | if let &0 | C0 | &2 = &0 {}
| ^^^^^^^^^^^^
Expand All @@ -33,7 +33,7 @@ LL | if let &(0 | 2) | C0 = &0 {}
| ^^^^^^^^^^^^^

error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:14:12
--> $DIR/unnested_or_patterns.rs:13:12
|
LL | if let &mut 0 | &mut 2 = &mut 0 {}
| ^^^^^^^^^^^^^^^
Expand All @@ -44,7 +44,7 @@ LL | if let &mut (0 | 2) = &mut 0 {}
| ^^^^^^^^^^^^

error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:15:12
--> $DIR/unnested_or_patterns.rs:14:12
|
LL | if let x @ 0 | x @ 2 = 0 {}
| ^^^^^^^^^^^^^
Expand All @@ -55,7 +55,7 @@ LL | if let x @ (0 | 2) = 0 {}
| ^^^^^^^^^^^

error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:16:12
--> $DIR/unnested_or_patterns.rs:15:12
|
LL | if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -66,7 +66,7 @@ LL | if let (0, 1 | 2 | 3) = (0, 0) {}
| ^^^^^^^^^^^^^^

error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:17:12
--> $DIR/unnested_or_patterns.rs:16:12
|
LL | if let (1, 0) | (2, 0) | (3, 0) = (0, 0) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -77,7 +77,7 @@ LL | if let (1 | 2 | 3, 0) = (0, 0) {}
| ^^^^^^^^^^^^^^

error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:18:12
--> $DIR/unnested_or_patterns.rs:17:12
|
LL | if let (x, ..) | (x, 1) | (x, 2) = (0, 1) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -88,7 +88,7 @@ LL | if let (x, ..) | (x, 1 | 2) = (0, 1) {}
| ^^^^^^^^^^^^^^^^^^^^

error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:19:12
--> $DIR/unnested_or_patterns.rs:18:12
|
LL | if let [0] | [1] = [0] {}
| ^^^^^^^^^
Expand All @@ -99,7 +99,7 @@ LL | if let [0 | 1] = [0] {}
| ^^^^^^^

error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:20:12
--> $DIR/unnested_or_patterns.rs:19:12
|
LL | if let [x, 0] | [x, 1] = [0, 1] {}
| ^^^^^^^^^^^^^^^
Expand All @@ -110,7 +110,7 @@ LL | if let [x, 0 | 1] = [0, 1] {}
| ^^^^^^^^^^

error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:21:12
--> $DIR/unnested_or_patterns.rs:20:12
|
LL | if let [x, 0] | [x, 1] | [x, 2] = [0, 1] {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -121,7 +121,7 @@ LL | if let [x, 0 | 1 | 2] = [0, 1] {}
| ^^^^^^^^^^^^^^

error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:22:12
--> $DIR/unnested_or_patterns.rs:21:12
|
LL | if let [x, ..] | [x, 1] | [x, 2] = [0, 1] {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -132,7 +132,7 @@ LL | if let [x, ..] | [x, 1 | 2] = [0, 1] {}
| ^^^^^^^^^^^^^^^^^^^^

error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:24:12
--> $DIR/unnested_or_patterns.rs:23:12
|
LL | if let TS(0, x) | TS(1, x) = TS(0, 0) {}
| ^^^^^^^^^^^^^^^^^^^
Expand All @@ -143,7 +143,7 @@ LL | if let TS(0 | 1, x) = TS(0, 0) {}
| ^^^^^^^^^^^^

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

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

error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:31:12
--> $DIR/unnested_or_patterns.rs:30:12
|
LL | if let S { x: 0, y } | S { y, x: 1 } = (S { x: 0, y: 1 }) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/ui/unnested_or_patterns2.fixed
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// run-rustfix

#![feature(or_patterns)]
#![feature(box_patterns)]
#![warn(clippy::unnested_or_patterns)]
#![allow(clippy::cognitive_complexity, clippy::match_ref_pats)]
Expand Down
1 change: 0 additions & 1 deletion tests/ui/unnested_or_patterns2.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// run-rustfix

#![feature(or_patterns)]
#![feature(box_patterns)]
#![warn(clippy::unnested_or_patterns)]
#![allow(clippy::cognitive_complexity, clippy::match_ref_pats)]
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/unnested_or_patterns2.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: unnested or-patterns
--> $DIR/unnested_or_patterns2.rs:10:12
--> $DIR/unnested_or_patterns2.rs:9:12
|
LL | if let Some(Some(0)) | Some(Some(1)) = None {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -11,7 +11,7 @@ LL | if let Some(Some(0 | 1)) = None {}
| ^^^^^^^^^^^^^^^^^

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

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

error: unnested or-patterns
--> $DIR/unnested_or_patterns2.rs:13:12
--> $DIR/unnested_or_patterns2.rs:12:12
|
LL | if let Some(Some(0) | Some(1 | 2)) = None {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -44,7 +44,7 @@ LL | if let Some(Some(0 | 1 | 2)) = None {}
| ^^^^^^^^^^^^^^^^^^^^^

error: unnested or-patterns
--> $DIR/unnested_or_patterns2.rs:14:12
--> $DIR/unnested_or_patterns2.rs:13:12
|
LL | if let ((0,),) | ((1,) | (2,),) = ((0,),) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -55,7 +55,7 @@ LL | if let ((0 | 1 | 2,),) = ((0,),) {}
| ^^^^^^^^^^^^^^^

error: unnested or-patterns
--> $DIR/unnested_or_patterns2.rs:15:12
--> $DIR/unnested_or_patterns2.rs:14:12
|
LL | if let 0 | (1 | 2) = 0 {}
| ^^^^^^^^^^^
Expand All @@ -66,7 +66,7 @@ LL | if let 0 | 1 | 2 = 0 {}
| ^^^^^^^^^

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

error: unnested or-patterns
--> $DIR/unnested_or_patterns2.rs:17:12
--> $DIR/unnested_or_patterns2.rs:16:12
|
LL | if let box box 0 | box (box 2 | box 4) = Box::new(Box::new(0)) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
6 changes: 0 additions & 6 deletions tests/ui/unnested_or_patterns3.rs

This file was deleted.

1 change: 0 additions & 1 deletion tests/ui/while_let_on_iterator.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#![warn(clippy::while_let_on_iterator)]
#![allow(clippy::never_loop, unreachable_code, unused_mut)]
#![feature(or_patterns)]

fn base() {
let mut iter = 1..20;
Expand Down
1 change: 0 additions & 1 deletion tests/ui/while_let_on_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#![warn(clippy::while_let_on_iterator)]
#![allow(clippy::never_loop, unreachable_code, unused_mut)]
#![feature(or_patterns)]

fn base() {
let mut iter = 1..20;
Expand Down
14 changes: 7 additions & 7 deletions tests/ui/while_let_on_iterator.stderr
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
error: this loop could be written as a `for` loop
--> $DIR/while_let_on_iterator.rs:9:5
--> $DIR/while_let_on_iterator.rs:8:5
|
LL | while let Option::Some(x) = iter.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in iter`
|
= note: `-D clippy::while-let-on-iterator` implied by `-D warnings`

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

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

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

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

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

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

0 comments on commit 2bc180e

Please sign in to comment.