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 c1d5108
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5455,7 +5455,6 @@ Released 2018-09-13
[`comparison_to_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#comparison_to_empty
[`const_is_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#const_is_empty
[`const_static_lifetime`]: https://rust-lang.github.io/rust-clippy/master/index.html#const_static_lifetime
[`contains_for_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#contains_for_slice
[`copy_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#copy_iterator
[`crate_in_macro_def`]: https://rust-lang.github.io/rust-clippy/master/index.html#crate_in_macro_def
[`create_dir`]: https://rust-lang.github.io/rust-clippy/master/index.html#create_dir
Expand Down Expand Up @@ -6021,6 +6020,7 @@ Released 2018-09-13
[`size_of_in_element_count`]: https://rust-lang.github.io/rust-clippy/master/index.html#size_of_in_element_count
[`size_of_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#size_of_ref
[`skip_while_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#skip_while_next
[`slice_iter_any`]: https://rust-lang.github.io/rust-clippy/master/index.html#slice_iter_any
[`slow_vector_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#slow_vector_initialization
[`stable_sort_primitive`]: https://rust-lang.github.io/rust-clippy/master/index.html#stable_sort_primitive
[`std_instead_of_alloc`]: https://rust-lang.github.io/rust-clippy/master/index.html#std_instead_of_alloc
Expand Down
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 c1d5108

Please sign in to comment.