Skip to content

Commit 66ae3b1

Browse files
committed
Rename if_let_redundant_pattern_matching to redundant_pattern_matching
Also, making the old one deprecated
1 parent 3b7c888 commit 66ae3b1

File tree

8 files changed

+43
-23
lines changed

8 files changed

+43
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ All notable changes to this project will be documented in this file.
816816
[`redundant_closure_call`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#redundant_closure_call
817817
[`redundant_field_names`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#redundant_field_names
818818
[`redundant_pattern`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#redundant_pattern
819+
[`redundant_pattern_matching`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#redundant_pattern_matching
819820
[`ref_in_deref`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#ref_in_deref
820821
[`regex_macro`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#regex_macro
821822
[`replace_consts`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#replace_consts

clippy_lints/src/deprecated_lints.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ macro_rules! declare_deprecated_lint {
1616

1717
/// **What it does:** Nothing. This lint has been deprecated.
1818
///
19-
/// **Deprecation reason:** This used to check for `assert!(a == b)` and recommend
19+
/// **Deprecation reason:** This used to check for `assert!(a == b)` and recommend
2020
/// replacement with `assert_eq!(a, b)`, but this is no longer needed after RFC 2011.
2121
declare_deprecated_lint! {
2222
pub SHOULD_ASSERT_EQ,
@@ -102,3 +102,13 @@ declare_deprecated_lint! {
102102
pub ASSIGN_OPS,
103103
"using compound assignment operators (e.g. `+=`) is harmless"
104104
}
105+
106+
/// **What it does:** Nothing. This lint has been deprecated.
107+
///
108+
/// **Deprecation reason:** The original rule will only lint for `if let`. After
109+
/// making it support to lint `match`, naming as `if let` is not suitable for it.
110+
/// So, this lint is deprecated.
111+
declare_deprecated_lint! {
112+
pub IF_LET_REDUNDANT_PATTERN_MATCHING,
113+
"this lint has been changed to redundant_pattern_matching"
114+
}

clippy_lints/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ pub mod formatting;
126126
pub mod functions;
127127
pub mod identity_conversion;
128128
pub mod identity_op;
129-
pub mod if_let_redundant_pattern_matching;
130129
pub mod if_not_else;
131130
pub mod indexing_slicing;
132131
pub mod infallible_destructuring_match;
@@ -180,6 +179,7 @@ pub mod ptr_offset_with_cast;
180179
pub mod question_mark;
181180
pub mod ranges;
182181
pub mod redundant_field_names;
182+
pub mod redundant_pattern_matching;
183183
pub mod reference;
184184
pub mod regex;
185185
pub mod replace_consts;
@@ -303,6 +303,10 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
303303
"assign_ops",
304304
"using compound assignment operators (e.g. `+=`) is harmless",
305305
);
306+
store.register_removed(
307+
"if_let_redundant_pattern_matching",
308+
"this lint has been changed to redundant_pattern_matching",
309+
);
306310
// end deprecated lints, do not remove this comment, it’s used in `update_lints`
307311

308312
reg.register_late_lint_pass(box serde_api::Serde);
@@ -402,7 +406,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
402406
reg.register_late_lint_pass(box missing_doc::MissingDoc::new());
403407
reg.register_late_lint_pass(box missing_inline::MissingInline);
404408
reg.register_late_lint_pass(box ok_if_let::Pass);
405-
reg.register_late_lint_pass(box if_let_redundant_pattern_matching::Pass);
409+
reg.register_late_lint_pass(box redundant_pattern_matching::Pass);
406410
reg.register_late_lint_pass(box partialeq_ne_impl::Pass);
407411
reg.register_early_lint_pass(box reference::Pass);
408412
reg.register_early_lint_pass(box reference::DerefPass);
@@ -565,7 +569,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
565569
functions::TOO_MANY_ARGUMENTS,
566570
identity_conversion::IDENTITY_CONVERSION,
567571
identity_op::IDENTITY_OP,
568-
if_let_redundant_pattern_matching::IF_LET_REDUNDANT_PATTERN_MATCHING,
569572
indexing_slicing::OUT_OF_BOUNDS_INDEXING,
570573
infallible_destructuring_match::INFALLIBLE_DESTRUCTURING_MATCH,
571574
infinite_iter::INFINITE_ITER,
@@ -680,6 +683,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
680683
ranges::RANGE_PLUS_ONE,
681684
ranges::RANGE_ZIP_WITH_LEN,
682685
redundant_field_names::REDUNDANT_FIELD_NAMES,
686+
redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING,
683687
reference::DEREF_ADDROF,
684688
reference::REF_IN_DEREF,
685689
regex::INVALID_REGEX,
@@ -749,7 +753,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
749753
excessive_precision::EXCESSIVE_PRECISION,
750754
formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING,
751755
formatting::SUSPICIOUS_ELSE_FORMATTING,
752-
if_let_redundant_pattern_matching::IF_LET_REDUNDANT_PATTERN_MATCHING,
753756
infallible_destructuring_match::INFALLIBLE_DESTRUCTURING_MATCH,
754757
len_zero::LEN_WITHOUT_IS_EMPTY,
755758
len_zero::LEN_ZERO,
@@ -800,6 +803,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
800803
ptr::PTR_ARG,
801804
question_mark::QUESTION_MARK,
802805
redundant_field_names::REDUNDANT_FIELD_NAMES,
806+
redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING,
803807
regex::REGEX_MACRO,
804808
regex::TRIVIAL_REGEX,
805809
returns::LET_AND_RETURN,

clippy_lints/src/if_let_redundant_pattern_matching.rs renamed to clippy_lints/src/redundant_pattern_matching.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ use crate::rustc_errors::Applicability;
3131
/// if let Err(_) = Err::<i32, i32>(42) {}
3232
/// if let None = None::<()> {}
3333
/// if let Some(_) = Some(42) {}
34+
/// match Ok::<i32, i32>(42) {
35+
/// Ok(_) => true,
36+
/// Err(_) => false,
37+
/// };
3438
/// ```
3539
///
3640
/// The more idiomatic use would be:
@@ -40,10 +44,11 @@ use crate::rustc_errors::Applicability;
4044
/// if Err::<i32, i32>(42).is_err() {}
4145
/// if None::<()>.is_none() {}
4246
/// if Some(42).is_some() {}
47+
/// Ok::<i32, i32>(42).is_ok();
4348
/// ```
4449
///
4550
declare_clippy_lint! {
46-
pub IF_LET_REDUNDANT_PATTERN_MATCHING,
51+
pub REDUNDANT_PATTERN_MATCHING,
4752
style,
4853
"use the proper utility function avoiding an `if let`"
4954
}
@@ -53,7 +58,7 @@ pub struct Pass;
5358

5459
impl LintPass for Pass {
5560
fn get_lints(&self) -> LintArray {
56-
lint_array!(IF_LET_REDUNDANT_PATTERN_MATCHING)
61+
lint_array!(REDUNDANT_PATTERN_MATCHING)
5762
}
5863
}
5964

@@ -101,7 +106,7 @@ fn find_sugg_for_if_let<'a, 'tcx>(
101106

102107
span_lint_and_then(
103108
cx,
104-
IF_LET_REDUNDANT_PATTERN_MATCHING,
109+
REDUNDANT_PATTERN_MATCHING,
105110
arms[0].pats[0].span,
106111
&format!("redundant pattern matching, consider using `{}`", good_method),
107112
|db| {
@@ -174,7 +179,7 @@ fn find_sugg_for_match<'a, 'tcx>(
174179
if let Some(good_method) = found_good_method {
175180
span_lint_and_then(
176181
cx,
177-
IF_LET_REDUNDANT_PATTERN_MATCHING,
182+
REDUNDANT_PATTERN_MATCHING,
178183
expr.span,
179184
&format!("redundant pattern matching, consider using `{}`", good_method),
180185
|db| {

tests/ui/matches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
#![warn(clippy::all)]
16-
#![allow(unused, clippy::if_let_redundant_pattern_matching)]
16+
#![allow(unused, clippy::redundant_pattern_matching)]
1717
#![warn(clippy::single_match_else, clippy::match_same_arms)]
1818

1919
enum ExprNode {

tests/ui/needless_pass_by_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
#![warn(clippy::needless_pass_by_value)]
14-
#![allow(dead_code, clippy::single_match, clippy::if_let_redundant_pattern_matching, clippy::many_single_char_names, clippy::option_option)]
14+
#![allow(dead_code, clippy::single_match, clippy::redundant_pattern_matching, clippy::many_single_char_names, clippy::option_option)]
1515

1616
use std::borrow::Borrow;
1717
use std::convert::AsRef;

tests/ui/if_let_redundant_pattern_matching.rs renamed to tests/ui/redundant_pattern_matching.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
#![warn(clippy::all)]
15-
#![warn(clippy::if_let_redundant_pattern_matching)]
15+
#![warn(clippy::redundant_pattern_matching)]
1616

1717

1818
fn main() {

tests/ui/if_let_redundant_pattern_matching.stderr renamed to tests/ui/redundant_pattern_matching.stderr

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
error: redundant pattern matching, consider using `is_ok()`
2-
--> $DIR/if_let_redundant_pattern_matching.rs:19:12
2+
--> $DIR/redundant_pattern_matching.rs:19:12
33
|
44
19 | if let Ok(_) = Ok::<i32, i32>(42) {}
55
| -------^^^^^------------------------ help: try this: `if Ok::<i32, i32>(42).is_ok()`
66
|
7-
= note: `-D clippy::if-let-redundant-pattern-matching` implied by `-D warnings`
7+
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
88

99
error: redundant pattern matching, consider using `is_err()`
10-
--> $DIR/if_let_redundant_pattern_matching.rs:21:12
10+
--> $DIR/redundant_pattern_matching.rs:21:12
1111
|
1212
21 | if let Err(_) = Err::<i32, i32>(42) {
1313
| _____- ^^^^^^
1414
22 | | }
1515
| |_____- help: try this: `if Err::<i32, i32>(42).is_err()`
1616

1717
error: redundant pattern matching, consider using `is_none()`
18-
--> $DIR/if_let_redundant_pattern_matching.rs:24:12
18+
--> $DIR/redundant_pattern_matching.rs:24:12
1919
|
2020
24 | if let None = None::<()> {
2121
| _____- ^^^^
2222
25 | | }
2323
| |_____- help: try this: `if None::<()>.is_none()`
2424

2525
error: redundant pattern matching, consider using `is_some()`
26-
--> $DIR/if_let_redundant_pattern_matching.rs:27:12
26+
--> $DIR/redundant_pattern_matching.rs:27:12
2727
|
2828
27 | if let Some(_) = Some(42) {
2929
| _____- ^^^^^^^
3030
28 | | }
3131
| |_____- help: try this: `if Some(42).is_some()`
3232

3333
error: redundant pattern matching, consider using `is_ok()`
34-
--> $DIR/if_let_redundant_pattern_matching.rs:46:5
34+
--> $DIR/redundant_pattern_matching.rs:46:5
3535
|
3636
46 | / match Ok::<i32, i32>(42) {
3737
47 | | Ok(_) => true,
@@ -40,7 +40,7 @@ error: redundant pattern matching, consider using `is_ok()`
4040
| |_____^ help: try this: `Ok::<i32, i32>(42).is_ok()`
4141

4242
error: redundant pattern matching, consider using `is_err()`
43-
--> $DIR/if_let_redundant_pattern_matching.rs:51:5
43+
--> $DIR/redundant_pattern_matching.rs:51:5
4444
|
4545
51 | / match Ok::<i32, i32>(42) {
4646
52 | | Ok(_) => false,
@@ -49,7 +49,7 @@ error: redundant pattern matching, consider using `is_err()`
4949
| |_____^ help: try this: `Ok::<i32, i32>(42).is_err()`
5050

5151
error: redundant pattern matching, consider using `is_err()`
52-
--> $DIR/if_let_redundant_pattern_matching.rs:56:5
52+
--> $DIR/redundant_pattern_matching.rs:56:5
5353
|
5454
56 | / match Err::<i32, i32>(42) {
5555
57 | | Ok(_) => false,
@@ -58,7 +58,7 @@ error: redundant pattern matching, consider using `is_err()`
5858
| |_____^ help: try this: `Err::<i32, i32>(42).is_err()`
5959

6060
error: redundant pattern matching, consider using `is_ok()`
61-
--> $DIR/if_let_redundant_pattern_matching.rs:61:5
61+
--> $DIR/redundant_pattern_matching.rs:61:5
6262
|
6363
61 | / match Err::<i32, i32>(42) {
6464
62 | | Ok(_) => true,
@@ -67,7 +67,7 @@ error: redundant pattern matching, consider using `is_ok()`
6767
| |_____^ help: try this: `Err::<i32, i32>(42).is_ok()`
6868

6969
error: redundant pattern matching, consider using `is_some()`
70-
--> $DIR/if_let_redundant_pattern_matching.rs:66:5
70+
--> $DIR/redundant_pattern_matching.rs:66:5
7171
|
7272
66 | / match Some(42) {
7373
67 | | Some(_) => true,
@@ -76,7 +76,7 @@ error: redundant pattern matching, consider using `is_some()`
7676
| |_____^ help: try this: `Some(42).is_some()`
7777

7878
error: redundant pattern matching, consider using `is_none()`
79-
--> $DIR/if_let_redundant_pattern_matching.rs:71:5
79+
--> $DIR/redundant_pattern_matching.rs:71:5
8080
|
8181
71 | / match None::<()> {
8282
72 | | Some(_) => false,

0 commit comments

Comments
 (0)