mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
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 https://github.com/rust-lang/rust/pull/78935#issuecomment-731564021 - [x] The resolution of the unresolved questions and a second crater run (https://github.com/rust-lang/rust/pull/78935#issuecomment-735412705) - 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 (https://github.com/rust-lang/rust/pull/80100). - [ ] An FCP on stabilization EDIT: Stabilization report is in https://github.com/rust-lang/rust/pull/79278#issuecomment-772815177
This commit is contained in:
commit
2bc180e888
13 changed files with 33 additions and 50 deletions
|
@ -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)]
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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) {}
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -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) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -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 {}
|
||||
| ^^^^^^^^^^^^
|
||||
|
@ -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 {}
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
@ -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 {}
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -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) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -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) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -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) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -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] {}
|
||||
| ^^^^^^^^^
|
||||
|
@ -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] {}
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
@ -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] {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -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] {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -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) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -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) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -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) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -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 }) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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 {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -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 {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -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 {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -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 {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -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,),) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -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 {}
|
||||
| ^^^^^^^^^^^
|
||||
|
@ -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) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -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)) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
#![warn(clippy::unnested_or_patterns)]
|
||||
|
||||
// Test that `unnested_or_patterns` does not trigger without enabling `or_patterns`
|
||||
fn main() {
|
||||
if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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`
|
||||
|
@ -7,37 +7,37 @@ LL | while let Option::Some(x) = iter.next() {
|
|||
= 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`
|
||||
|
|
Loading…
Reference in a new issue