Skip to content

Commit 298df70

Browse files
committed
Auto merge of rust-lang#5061 - ThibsG:UselessMatch3664, r=flip1995
Add new lint: match with a single binding statement This lint catches `match` statements that binds to only one block and could be rewritten using a simple `let` statement. Lint name: MATCH_SINGLE_BINDING fixes: rust-lang#3664 changelog: add lint for match with single binding statement
2 parents d33c603 + 00904cb commit 298df70

16 files changed

+486
-100
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,7 @@ Released 2018-09-13
12171217
[`match_overlapping_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_overlapping_arm
12181218
[`match_ref_pats`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_ref_pats
12191219
[`match_same_arms`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
1220+
[`match_single_binding`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_single_binding
12201221
[`match_wild_err_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_wild_err_arm
12211222
[`maybe_infinite_iter`]: https://rust-lang.github.io/rust-clippy/master/index.html#maybe_infinite_iter
12221223
[`mem_discriminant_non_enum`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_discriminant_non_enum

README.md

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

77
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
88

9-
[There are 351 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
9+
[There are 352 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1010

1111
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1212

clippy_lints/src/infallible_destructuring_match.rs

-77
This file was deleted.

clippy_lints/src/lib.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ pub mod if_let_some_result;
218218
pub mod if_not_else;
219219
pub mod implicit_return;
220220
pub mod indexing_slicing;
221-
pub mod infallible_destructuring_match;
222221
pub mod infinite_iter;
223222
pub mod inherent_impl;
224223
pub mod inherent_to_string;
@@ -555,7 +554,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
555554
&implicit_return::IMPLICIT_RETURN,
556555
&indexing_slicing::INDEXING_SLICING,
557556
&indexing_slicing::OUT_OF_BOUNDS_INDEXING,
558-
&infallible_destructuring_match::INFALLIBLE_DESTRUCTURING_MATCH,
559557
&infinite_iter::INFINITE_ITER,
560558
&infinite_iter::MAYBE_INFINITE_ITER,
561559
&inherent_impl::MULTIPLE_INHERENT_IMPL,
@@ -600,10 +598,12 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
600598
&map_clone::MAP_CLONE,
601599
&map_unit_fn::OPTION_MAP_UNIT_FN,
602600
&map_unit_fn::RESULT_MAP_UNIT_FN,
601+
&matches::INFALLIBLE_DESTRUCTURING_MATCH,
603602
&matches::MATCH_AS_REF,
604603
&matches::MATCH_BOOL,
605604
&matches::MATCH_OVERLAPPING_ARM,
606605
&matches::MATCH_REF_PATS,
606+
&matches::MATCH_SINGLE_BINDING,
607607
&matches::MATCH_WILD_ERR_ARM,
608608
&matches::SINGLE_MATCH,
609609
&matches::SINGLE_MATCH_ELSE,
@@ -864,7 +864,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
864864
store.register_late_pass(|| box types::Casts);
865865
let type_complexity_threshold = conf.type_complexity_threshold;
866866
store.register_late_pass(move || box types::TypeComplexity::new(type_complexity_threshold));
867-
store.register_late_pass(|| box matches::Matches);
867+
store.register_late_pass(|| box matches::Matches::default());
868868
store.register_late_pass(|| box minmax::MinMaxPass);
869869
store.register_late_pass(|| box open_options::OpenOptions);
870870
store.register_late_pass(|| box zero_div_zero::ZeroDiv);
@@ -941,7 +941,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
941941
store.register_late_pass(|| box question_mark::QuestionMark);
942942
store.register_late_pass(|| box suspicious_trait_impl::SuspiciousImpl);
943943
store.register_late_pass(|| box map_unit_fn::MapUnit);
944-
store.register_late_pass(|| box infallible_destructuring_match::InfallibleDestructingMatch);
945944
store.register_late_pass(|| box inherent_impl::MultipleInherentImpl::default());
946945
store.register_late_pass(|| box neg_cmp_op_on_partial_ord::NoNegCompOpForPartialOrd);
947946
store.register_late_pass(|| box unwrap::Unwrap);
@@ -1166,7 +1165,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11661165
LintId::of(&identity_op::IDENTITY_OP),
11671166
LintId::of(&if_let_some_result::IF_LET_SOME_RESULT),
11681167
LintId::of(&indexing_slicing::OUT_OF_BOUNDS_INDEXING),
1169-
LintId::of(&infallible_destructuring_match::INFALLIBLE_DESTRUCTURING_MATCH),
11701168
LintId::of(&infinite_iter::INFINITE_ITER),
11711169
LintId::of(&inherent_to_string::INHERENT_TO_STRING),
11721170
LintId::of(&inherent_to_string::INHERENT_TO_STRING_SHADOW_DISPLAY),
@@ -1201,10 +1199,12 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
12011199
LintId::of(&map_clone::MAP_CLONE),
12021200
LintId::of(&map_unit_fn::OPTION_MAP_UNIT_FN),
12031201
LintId::of(&map_unit_fn::RESULT_MAP_UNIT_FN),
1202+
LintId::of(&matches::INFALLIBLE_DESTRUCTURING_MATCH),
12041203
LintId::of(&matches::MATCH_AS_REF),
12051204
LintId::of(&matches::MATCH_BOOL),
12061205
LintId::of(&matches::MATCH_OVERLAPPING_ARM),
12071206
LintId::of(&matches::MATCH_REF_PATS),
1207+
LintId::of(&matches::MATCH_SINGLE_BINDING),
12081208
LintId::of(&matches::MATCH_WILD_ERR_ARM),
12091209
LintId::of(&matches::SINGLE_MATCH),
12101210
LintId::of(&matches::WILDCARD_IN_OR_PATTERNS),
@@ -1382,7 +1382,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13821382
LintId::of(&functions::DOUBLE_MUST_USE),
13831383
LintId::of(&functions::MUST_USE_UNIT),
13841384
LintId::of(&if_let_some_result::IF_LET_SOME_RESULT),
1385-
LintId::of(&infallible_destructuring_match::INFALLIBLE_DESTRUCTURING_MATCH),
13861385
LintId::of(&inherent_to_string::INHERENT_TO_STRING),
13871386
LintId::of(&len_zero::LEN_WITHOUT_IS_EMPTY),
13881387
LintId::of(&len_zero::LEN_ZERO),
@@ -1395,6 +1394,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13951394
LintId::of(&loops::WHILE_LET_ON_ITERATOR),
13961395
LintId::of(&main_recursion::MAIN_RECURSION),
13971396
LintId::of(&map_clone::MAP_CLONE),
1397+
LintId::of(&matches::INFALLIBLE_DESTRUCTURING_MATCH),
13981398
LintId::of(&matches::MATCH_BOOL),
13991399
LintId::of(&matches::MATCH_OVERLAPPING_ARM),
14001400
LintId::of(&matches::MATCH_REF_PATS),
@@ -1483,6 +1483,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
14831483
LintId::of(&map_unit_fn::OPTION_MAP_UNIT_FN),
14841484
LintId::of(&map_unit_fn::RESULT_MAP_UNIT_FN),
14851485
LintId::of(&matches::MATCH_AS_REF),
1486+
LintId::of(&matches::MATCH_SINGLE_BINDING),
14861487
LintId::of(&matches::WILDCARD_IN_OR_PATTERNS),
14871488
LintId::of(&methods::CHARS_NEXT_CMP),
14881489
LintId::of(&methods::CLONE_ON_COPY),

0 commit comments

Comments
 (0)