@@ -37,6 +37,7 @@ mod inspect_for_each;
3737mod into_iter_on_ref;
3838mod is_digit_ascii_radix;
3939mod is_empty;
40+ mod iter_any;
4041mod iter_cloned_collect;
4142mod iter_count;
4243mod iter_filter;
@@ -100,7 +101,6 @@ mod single_char_add_str;
100101mod single_char_insert_string;
101102mod single_char_push_string;
102103mod skip_while_next;
103- mod slice_iter_any;
104104mod stable_sort_primitive;
105105mod str_split;
106106mod str_splitn;
@@ -4310,6 +4310,29 @@ declare_clippy_lint! {
43104310 "using `contains()` instead of `iter().any()` on `u8`/`i8` slices is more fast"
43114311}
43124312
4313+ declare_clippy_lint ! {
4314+ /// ### What it does
4315+ /// Checks for usage of `iter().any()` when it can be replaced with `contains()` and suggests doing so.
4316+ ///
4317+ /// ### Why is this bad?
4318+ /// It makes the code less readable.
4319+ ///
4320+ /// ### Example
4321+ /// ```no_run
4322+ /// let values = &[1, 2, 3];
4323+ /// let _ = values.iter().any(|&v| v == 2);
4324+ /// ```
4325+ /// Use instead:
4326+ /// ```no_run
4327+ /// let values = &[1, 2, 3];
4328+ /// let _ = values.contains(&2);
4329+ /// ```
4330+ #[ clippy:: version = "1.85.0" ]
4331+ pub UNNECESSARY_ITER_ANY ,
4332+ style,
4333+ "using `contains()` instead of `iter().any()` is more readable"
4334+ }
4335+
43134336pub struct Methods {
43144337 avoid_breaking_exported_api : bool ,
43154338 msrv : Msrv ,
@@ -4476,6 +4499,7 @@ impl_lint_pass!(Methods => [
44764499 MAP_WITH_UNUSED_ARGUMENT_OVER_RANGES ,
44774500 UNNECESSARY_MAP_OR ,
44784501 SLICE_ITER_ANY ,
4502+ UNNECESSARY_ITER_ANY ,
44794503] ) ;
44804504
44814505/// Extracts a method call name, args, and `Span` of the method name.
@@ -4710,7 +4734,7 @@ impl Methods {
47104734 ( "any" , [ arg] ) => {
47114735 unused_enumerate_index:: check ( cx, expr, recv, arg) ;
47124736 needless_character_iteration:: check ( cx, expr, recv, arg, false ) ;
4713- slice_iter_any :: check ( cx, expr) ;
4737+ iter_any :: check ( cx, expr) ;
47144738 match method_call ( recv) {
47154739 Some ( ( "cloned" , recv2, [ ] , _, _) ) => iter_overeager_cloned:: check (
47164740 cx,
0 commit comments