diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ba2c51623b..f49980f712b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1348,11 +1348,11 @@ Released 2018-09-13 [`map_flatten`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten [`match_as_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_as_ref [`match_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_bool +[`match_on_vec_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_on_vec_items [`match_overlapping_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_overlapping_arm [`match_ref_pats`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_ref_pats [`match_same_arms`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms [`match_single_binding`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_single_binding -[`match_vec_item`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_vec_item [`match_wild_err_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_wild_err_arm [`maybe_infinite_iter`]: https://rust-lang.github.io/rust-clippy/master/index.html#maybe_infinite_iter [`mem_discriminant_non_enum`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_discriminant_non_enum diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 79bf13a1005..a72fad86227 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -249,7 +249,7 @@ mod macro_use; mod main_recursion; mod map_clone; mod map_unit_fn; -mod match_vec_item; +mod match_on_vec_items; mod matches; mod mem_discriminant; mod mem_forget; @@ -630,7 +630,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &map_clone::MAP_CLONE, &map_unit_fn::OPTION_MAP_UNIT_FN, &map_unit_fn::RESULT_MAP_UNIT_FN, - &match_vec_item::MATCH_VEC_ITEM, + &match_on_vec_items::MATCH_ON_VEC_ITEMS, &matches::INFALLIBLE_DESTRUCTURING_MATCH, &matches::MATCH_AS_REF, &matches::MATCH_BOOL, @@ -1062,7 +1062,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: store.register_late_pass(|| box future_not_send::FutureNotSend); store.register_late_pass(|| box utils::internal_lints::CollapsibleCalls); store.register_late_pass(|| box if_let_mutex::IfLetMutex); - store.register_late_pass(|| box match_vec_item::MatchVecItem); + store.register_late_pass(|| box match_on_vec_items::MatchOnVecItems); store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![ LintId::of(&arithmetic::FLOAT_ARITHMETIC), @@ -1280,7 +1280,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&map_clone::MAP_CLONE), LintId::of(&map_unit_fn::OPTION_MAP_UNIT_FN), LintId::of(&map_unit_fn::RESULT_MAP_UNIT_FN), - LintId::of(&match_vec_item::MATCH_VEC_ITEM), + LintId::of(&match_on_vec_items::MATCH_ON_VEC_ITEMS), LintId::of(&matches::INFALLIBLE_DESTRUCTURING_MATCH), LintId::of(&matches::MATCH_AS_REF), LintId::of(&matches::MATCH_BOOL), @@ -1473,7 +1473,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&loops::WHILE_LET_ON_ITERATOR), LintId::of(&main_recursion::MAIN_RECURSION), LintId::of(&map_clone::MAP_CLONE), - LintId::of(&match_vec_item::MATCH_VEC_ITEM), + LintId::of(&match_on_vec_items::MATCH_ON_VEC_ITEMS), LintId::of(&matches::INFALLIBLE_DESTRUCTURING_MATCH), LintId::of(&matches::MATCH_BOOL), LintId::of(&matches::MATCH_OVERLAPPING_ARM), diff --git a/clippy_lints/src/match_vec_item.rs b/clippy_lints/src/match_on_vec_items.rs similarity index 91% rename from clippy_lints/src/match_vec_item.rs rename to clippy_lints/src/match_on_vec_items.rs index 07121dedefe..167b4abd93d 100644 --- a/clippy_lints/src/match_vec_item.rs +++ b/clippy_lints/src/match_on_vec_items.rs @@ -37,14 +37,14 @@ declare_clippy_lint! { /// _ => {}, /// } /// ``` - pub MATCH_VEC_ITEM, + pub MATCH_ON_VEC_ITEMS, style, - "match vector by indexing can panic" + "matching on vector elements can panic" } -declare_lint_pass!(MatchVecItem => [MATCH_VEC_ITEM]); +declare_lint_pass!(MatchOnVecItems => [MATCH_ON_VEC_ITEMS]); -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MatchVecItem { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MatchOnVecItems { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) { if_chain! { if !in_external_macro(cx.sess(), expr.span); @@ -56,7 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MatchVecItem { let mut applicability = Applicability::MaybeIncorrect; span_lint_and_sugg( cx, - MATCH_VEC_ITEM, + MATCH_ON_VEC_ITEMS, match_expr.span, "indexing vector may panic. Consider using `get`", "try this", diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 7c9e0448950..17f94411298 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -1144,6 +1144,13 @@ pub static ref ALL_LINTS: Vec = vec![ deprecation: None, module: "matches", }, + Lint { + name: "match_on_vec_items", + group: "style", + desc: "matching on vector elements can panic", + deprecation: None, + module: "match_on_vec_items", + }, Lint { name: "match_overlapping_arm", group: "style", @@ -1172,13 +1179,6 @@ pub static ref ALL_LINTS: Vec = vec![ deprecation: None, module: "matches", }, - Lint { - name: "match_vec_item", - group: "style", - desc: "match vector by indexing can panic", - deprecation: None, - module: "match_vec_item", - }, Lint { name: "match_wild_err_arm", group: "style", diff --git a/tests/ui/match_vec_item.rs b/tests/ui/match_on_vec_items.rs similarity index 98% rename from tests/ui/match_vec_item.rs rename to tests/ui/match_on_vec_items.rs index d00d0bc2fe5..02b6da03439 100644 --- a/tests/ui/match_vec_item.rs +++ b/tests/ui/match_on_vec_items.rs @@ -1,4 +1,4 @@ -#![warn(clippy::match_vec_item)] +#![warn(clippy::match_on_vec_items)] fn main() { match_with_wildcard(); diff --git a/tests/ui/match_vec_item.stderr b/tests/ui/match_on_vec_items.stderr similarity index 76% rename from tests/ui/match_vec_item.stderr rename to tests/ui/match_on_vec_items.stderr index 2da2eaeee9b..0e53a58f141 100644 --- a/tests/ui/match_vec_item.stderr +++ b/tests/ui/match_on_vec_items.stderr @@ -1,49 +1,49 @@ error: indexing vector may panic. Consider using `get` - --> $DIR/match_vec_item.rs:18:11 + --> $DIR/match_on_vec_items.rs:18:11 | LL | match arr[idx] { | ^^^^^^^^ help: try this: `arr.get(idx)` | - = note: `-D clippy::match-vec-item` implied by `-D warnings` + = note: `-D clippy::match-on-vec-items` implied by `-D warnings` error: indexing vector may panic. Consider using `get` - --> $DIR/match_vec_item.rs:25:11 + --> $DIR/match_on_vec_items.rs:25:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try this: `arr.get(range)` error: indexing vector may panic. Consider using `get` - --> $DIR/match_vec_item.rs:38:11 + --> $DIR/match_on_vec_items.rs:38:11 | LL | match arr[idx] { | ^^^^^^^^ help: try this: `arr.get(idx)` error: indexing vector may panic. Consider using `get` - --> $DIR/match_vec_item.rs:45:11 + --> $DIR/match_on_vec_items.rs:45:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try this: `arr.get(range)` error: indexing vector may panic. Consider using `get` - --> $DIR/match_vec_item.rs:58:11 + --> $DIR/match_on_vec_items.rs:58:11 | LL | match arr[idx] { | ^^^^^^^^ help: try this: `arr.get(idx)` error: indexing vector may panic. Consider using `get` - --> $DIR/match_vec_item.rs:65:11 + --> $DIR/match_on_vec_items.rs:65:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try this: `arr.get(range)` error: indexing vector may panic. Consider using `get` - --> $DIR/match_vec_item.rs:78:11 + --> $DIR/match_on_vec_items.rs:78:11 | LL | match arr[idx] { | ^^^^^^^^ help: try this: `arr.get(idx)` error: indexing vector may panic. Consider using `get` - --> $DIR/match_vec_item.rs:85:11 + --> $DIR/match_on_vec_items.rs:85:11 | LL | match arr[range] { | ^^^^^^^^^^ help: try this: `arr.get(range)`