From 149e7016cfcc7b94b3ff791e1a2605e5e6d77e57 Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Fri, 13 Dec 2024 08:43:08 +0900 Subject: [PATCH] rename contains_for_slice to slice_iter_any --- clippy_lints/src/declared_lints.rs | 2 +- clippy_lints/src/methods/mod.rs | 8 ++++---- .../methods/{contains_for_slice.rs => slice_iter_any.rs} | 4 ++-- tests/ui/{contains_for_slice.rs => slice_iter_any.rs} | 2 +- .../{contains_for_slice.stderr => slice_iter_any.stderr} | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) rename clippy_lints/src/methods/{contains_for_slice.rs => slice_iter_any.rs} (94%) rename tests/ui/{contains_for_slice.rs => slice_iter_any.rs} (96%) rename tests/ui/{contains_for_slice.stderr => slice_iter_any.stderr} (63%) diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 8684ee279e8d..6789d9e75006 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -371,7 +371,6 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::methods::CLONE_ON_REF_PTR_INFO, crate::methods::COLLAPSIBLE_STR_REPLACE_INFO, crate::methods::CONST_IS_EMPTY_INFO, - crate::methods::CONTAINS_FOR_SLICE_INFO, crate::methods::DRAIN_COLLECT_INFO, crate::methods::ERR_EXPECT_INFO, crate::methods::EXPECT_FUN_CALL_INFO, @@ -465,6 +464,7 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::methods::SHOULD_IMPLEMENT_TRAIT_INFO, crate::methods::SINGLE_CHAR_ADD_STR_INFO, crate::methods::SKIP_WHILE_NEXT_INFO, + crate::methods::SLICE_ITER_ANY_INFO, crate::methods::STABLE_SORT_PRIMITIVE_INFO, crate::methods::STRING_EXTEND_CHARS_INFO, crate::methods::STRING_LIT_CHARS_ANY_INFO, diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index f827a8c640fb..de298b5db890 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -14,7 +14,6 @@ mod clone_on_copy; mod clone_on_ref_ptr; mod cloned_instead_of_copied; mod collapsible_str_replace; -mod contains_for_slice; mod drain_collect; mod err_expect; mod expect_fun_call; @@ -101,6 +100,7 @@ mod single_char_add_str; mod single_char_insert_string; mod single_char_push_string; mod skip_while_next; +mod slice_iter_any; mod stable_sort_primitive; mod str_split; mod str_splitn; @@ -4305,7 +4305,7 @@ declare_clippy_lint! { /// } /// ``` #[clippy::version = "1.85.0"] - pub CONTAINS_FOR_SLICE, + pub SLICE_ITER_ANY, perf, "using `contains()` instead of `iter().any()` on u8/i8 slices is more efficient" } @@ -4475,7 +4475,7 @@ impl_lint_pass!(Methods => [ MAP_ALL_ANY_IDENTITY, MAP_WITH_UNUSED_ARGUMENT_OVER_RANGES, UNNECESSARY_MAP_OR, - CONTAINS_FOR_SLICE, + SLICE_ITER_ANY, ]); /// Extracts a method call name, args, and `Span` of the method name. @@ -4710,7 +4710,7 @@ impl Methods { ("any", [arg]) => { unused_enumerate_index::check(cx, expr, recv, arg); needless_character_iteration::check(cx, expr, recv, arg, false); - contains_for_slice::check(cx, expr); + slice_iter_any::check(cx, expr); match method_call(recv) { Some(("cloned", recv2, [], _, _)) => iter_overeager_cloned::check( cx, diff --git a/clippy_lints/src/methods/contains_for_slice.rs b/clippy_lints/src/methods/slice_iter_any.rs similarity index 94% rename from clippy_lints/src/methods/contains_for_slice.rs rename to clippy_lints/src/methods/slice_iter_any.rs index 714dd2c7dfa4..849f760e4c77 100644 --- a/clippy_lints/src/methods/contains_for_slice.rs +++ b/clippy_lints/src/methods/slice_iter_any.rs @@ -3,7 +3,7 @@ use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; use rustc_middle::ty::{self}; -use super::{CONTAINS_FOR_SLICE, method_call}; +use super::{SLICE_ITER_ANY, method_call}; pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { if !expr.span.from_expansion() @@ -31,7 +31,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { { span_lint( cx, - CONTAINS_FOR_SLICE, + SLICE_ITER_ANY, expr.span, "using `contains()` instead of `iter().any()` on u8/i8 slices is more efficient", ); diff --git a/tests/ui/contains_for_slice.rs b/tests/ui/slice_iter_any.rs similarity index 96% rename from tests/ui/contains_for_slice.rs rename to tests/ui/slice_iter_any.rs index ab69395c8a89..1489362d75f5 100644 --- a/tests/ui/contains_for_slice.rs +++ b/tests/ui/slice_iter_any.rs @@ -1,4 +1,4 @@ -#![warn(clippy::contains_for_slice)] +#![warn(clippy::slice_iter_any)] fn main() { let vec: Vec = vec![1, 2, 3, 4, 5, 6]; diff --git a/tests/ui/contains_for_slice.stderr b/tests/ui/slice_iter_any.stderr similarity index 63% rename from tests/ui/contains_for_slice.stderr rename to tests/ui/slice_iter_any.stderr index 0f8b3f483084..13bdf235d2f3 100644 --- a/tests/ui/contains_for_slice.stderr +++ b/tests/ui/slice_iter_any.stderr @@ -1,14 +1,14 @@ error: using `contains()` instead of `iter().any()` on u8/i8 slices is more efficient - --> tests/ui/contains_for_slice.rs:6:13 + --> tests/ui/slice_iter_any.rs:6:13 | LL | let _ = values.iter().any(|&v| v == 4); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::contains-for-slice` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::contains_for_slice)]` + = note: `-D clippy::slice-iter-any` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::slice_iter_any)]` error: using `contains()` instead of `iter().any()` on u8/i8 slices is more efficient - --> tests/ui/contains_for_slice.rs:29:5 + --> tests/ui/slice_iter_any.rs:29:5 | LL | values.iter().any(|&v| v == 10) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^