Skip to content

Commit 7caf0c9

Browse files
committed
Deprecate match_on_vec_items lint
This lint does more harm than good: in its description, it proposes to rewrite `match` on `Vec<_>` indexes or slices by a version which cannot panic but masks the failure by choosing the default variant. The `clippy::indexing_slicing` restriction lint covers those cases more safely, by suggesting to use a non-panicking version to retrieve the value from the container, without suggesting to fallback to the default success variant in case of failure.
1 parent a8b1782 commit 7caf0c9

File tree

8 files changed

+10
-305
lines changed

8 files changed

+10
-305
lines changed

clippy_lints/src/declared_lints.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ pub static LINTS: &[&crate::LintInfo] = &[
344344
crate::matches::MATCH_AS_REF_INFO,
345345
crate::matches::MATCH_BOOL_INFO,
346346
crate::matches::MATCH_LIKE_MATCHES_MACRO_INFO,
347-
crate::matches::MATCH_ON_VEC_ITEMS_INFO,
348347
crate::matches::MATCH_OVERLAPPING_ARM_INFO,
349348
crate::matches::MATCH_REF_PATS_INFO,
350349
crate::matches::MATCH_SAME_ARMS_INFO,

clippy_lints/src/deprecated_lints.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ declare_with_version! { DEPRECATED(DEPRECATED_VERSION): &[(&str, &str)] = &[
4242
("clippy::wrong_pub_self_convention", "`clippy::wrong_self_convention` now covers this case via the `avoid-breaking-exported-api` config"),
4343
#[clippy::version = "1.86.0"]
4444
("clippy::option_map_or_err_ok", "`clippy::manual_ok_or` covers this case"),
45+
#[clippy::version = "1.86.0"]
46+
("clippy::match_on_vec_items", "`clippy::indexing_slicing` covers indexing and slicing on `Vec<_>`"),
4547
// end deprecated lints. used by `cargo dev deprecate_lint`
4648
]}
4749

clippy_lints/src/matches/match_on_vec_items.rs

Lines changed: 0 additions & 50 deletions
This file was deleted.

clippy_lints/src/matches/mod.rs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ mod manual_utils;
88
mod match_as_ref;
99
mod match_bool;
1010
mod match_like_matches;
11-
mod match_on_vec_items;
1211
mod match_ref_pats;
1312
mod match_same_arms;
1413
mod match_single_binding;
@@ -722,42 +721,6 @@ declare_clippy_lint! {
722721
"finds patterns that can be encoded more concisely with `Option::unwrap_or` or `Result::unwrap_or`"
723722
}
724723

725-
declare_clippy_lint! {
726-
/// ### What it does
727-
/// Checks for `match vec[idx]` or `match vec[n..m]`.
728-
///
729-
/// ### Why is this bad?
730-
/// This can panic at runtime.
731-
///
732-
/// ### Example
733-
/// ```rust, no_run
734-
/// let arr = vec![0, 1, 2, 3];
735-
/// let idx = 1;
736-
///
737-
/// match arr[idx] {
738-
/// 0 => println!("{}", 0),
739-
/// 1 => println!("{}", 3),
740-
/// _ => {},
741-
/// }
742-
/// ```
743-
///
744-
/// Use instead:
745-
/// ```rust, no_run
746-
/// let arr = vec![0, 1, 2, 3];
747-
/// let idx = 1;
748-
///
749-
/// match arr.get(idx) {
750-
/// Some(0) => println!("{}", 0),
751-
/// Some(1) => println!("{}", 3),
752-
/// _ => {},
753-
/// }
754-
/// ```
755-
#[clippy::version = "1.45.0"]
756-
pub MATCH_ON_VEC_ITEMS,
757-
pedantic,
758-
"matching on vector elements can panic"
759-
}
760-
761724
declare_clippy_lint! {
762725
/// ### What it does
763726
/// Checks for `match` expressions modifying the case of a string with non-compliant arms
@@ -1040,7 +1003,6 @@ impl_lint_pass!(Matches => [
10401003
NEEDLESS_MATCH,
10411004
COLLAPSIBLE_MATCH,
10421005
MANUAL_UNWRAP_OR,
1043-
MATCH_ON_VEC_ITEMS,
10441006
MATCH_STR_CASE_MISMATCH,
10451007
SIGNIFICANT_DROP_IN_SCRUTINEE,
10461008
TRY_ERR,
@@ -1118,7 +1080,6 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
11181080
match_wild_enum::check(cx, ex, arms);
11191081
match_as_ref::check(cx, ex, arms, expr);
11201082
needless_match::check_match(cx, ex, arms, expr);
1121-
match_on_vec_items::check(cx, ex);
11221083
match_str_case_mismatch::check(cx, ex, arms);
11231084
redundant_guards::check(cx, arms, &self.msrv);
11241085

tests/ui/deprecated.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
#![warn(clippy::pub_enum_variant_names)] //~ ERROR: lint `clippy::pub_enum_variant_names`
1717
#![warn(clippy::wrong_pub_self_convention)] //~ ERROR: lint `clippy::wrong_pub_self_convention`
1818
#![warn(clippy::option_map_or_err_ok)] //~ ERROR: lint `clippy::option_map_or_err_ok`
19+
#![warn(clippy::match_on_vec_items)] //~ ERROR: lint `clippy::match_on_vec_items`
1920

2021
fn main() {}

tests/ui/deprecated.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,11 @@ error: lint `clippy::option_map_or_err_ok` has been removed: `clippy::manual_ok_
8585
LL | #![warn(clippy::option_map_or_err_ok)]
8686
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8787

88-
error: aborting due to 14 previous errors
88+
error: lint `clippy::match_on_vec_items` has been removed: `clippy::indexing_slicing` covers indexing and slicing on `Vec<_>`
89+
--> tests/ui/deprecated.rs:19:9
90+
|
91+
LL | #![warn(clippy::match_on_vec_items)]
92+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
93+
94+
error: aborting due to 15 previous errors
8995

tests/ui/match_on_vec_items.rs

Lines changed: 0 additions & 161 deletions
This file was deleted.

tests/ui/match_on_vec_items.stderr

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)