Skip to content

Commit

Permalink
rename contains_for_slice to slice_iter_any
Browse files Browse the repository at this point in the history
  • Loading branch information
lapla-cogito committed Dec 12, 2024
1 parent c52ebf2 commit 149e701
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/declared_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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"
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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",
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![warn(clippy::contains_for_slice)]
#![warn(clippy::slice_iter_any)]

fn main() {
let vec: Vec<u8> = vec![1, 2, 3, 4, 5, 6];
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down

0 comments on commit 149e701

Please sign in to comment.