@@ -42,7 +42,6 @@ mod iter_kv_map;
4242mod iter_next_slice;
4343mod iter_nth;
4444mod iter_nth_zero;
45- mod iter_on_single_or_empty_collections;
4645mod iter_overeager_cloned;
4746mod iter_skip_next;
4847mod iter_skip_zero;
@@ -83,6 +82,7 @@ mod single_char_add_str;
8382mod single_char_insert_string;
8483mod single_char_pattern;
8584mod single_char_push_string;
85+ mod single_or_empty_collections_iter;
8686mod skip_while_next;
8787mod stable_sort_primitive;
8888mod str_splitn;
@@ -2430,15 +2430,15 @@ declare_clippy_lint! {
24302430
24312431declare_clippy_lint ! {
24322432 /// ### What it does
2433- ///
2434- /// Checks for calls to `iter`, `iter_mut` or `into_iter` on collections containing a single item
2433+ /// Checks for calls to `iter`, `iter_mut` or `into_iter` on collections containing a single item.
24352434 ///
24362435 /// ### Why is this bad?
2436+ /// It is simpler to use the once function from the standard library.
24372437 ///
2438- /// It is simpler to use the once function from the standard library:
2438+ /// ### Known problems
2439+ /// The type of the resulting iterator might become incompatible with its usage.
24392440 ///
24402441 /// ### Example
2441- ///
24422442 /// ```rust
24432443 /// let a = [123].iter();
24442444 /// let b = Some(123).into_iter();
@@ -2449,27 +2449,23 @@ declare_clippy_lint! {
24492449 /// let a = iter::once(&123);
24502450 /// let b = iter::once(123);
24512451 /// ```
2452- ///
2453- /// ### Known problems
2454- ///
2455- /// The type of the resulting iterator might become incompatible with its usage
24562452 #[ clippy:: version = "1.65.0" ]
24572453 pub ITER_ON_SINGLE_ITEMS ,
2458- nursery ,
2454+ pedantic ,
24592455 "Iterator for array of length 1"
24602456}
24612457
24622458declare_clippy_lint ! {
24632459 /// ### What it does
2464- ///
2465- /// Checks for calls to `iter`, `iter_mut` or `into_iter` on empty collections
2460+ /// Checks for calls to `iter`, `iter_mut` or `into_iter` on empty collections.
24662461 ///
24672462 /// ### Why is this bad?
2463+ /// It is simpler to use the empty function from the standard library.
24682464 ///
2469- /// It is simpler to use the empty function from the standard library:
2465+ /// ### Known problems
2466+ /// The type of the resulting iterator might become incompatible with its usage.
24702467 ///
24712468 /// ### Example
2472- ///
24732469 /// ```rust
24742470 /// use std::{slice, option};
24752471 /// let a: slice::Iter<i32> = [].iter();
@@ -2481,13 +2477,9 @@ declare_clippy_lint! {
24812477 /// let a: iter::Empty<i32> = iter::empty();
24822478 /// let b: iter::Empty<i32> = iter::empty();
24832479 /// ```
2484- ///
2485- /// ### Known problems
2486- ///
2487- /// The type of the resulting iterator might become incompatible with its usage
24882480 #[ clippy:: version = "1.65.0" ]
24892481 pub ITER_ON_EMPTY_COLLECTIONS ,
2490- nursery ,
2482+ pedantic ,
24912483 "Iterator for empty array"
24922484}
24932485
@@ -3629,6 +3621,8 @@ fn method_call<'tcx>(
36293621
36303622impl < ' tcx > LateLintPass < ' tcx > for Methods {
36313623 fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx hir:: Expr < ' _ > ) {
3624+ single_or_empty_collections_iter:: check ( cx, expr, & self . msrv ) ;
3625+
36323626 if expr. span . from_expansion ( ) {
36333627 return ;
36343628 }
@@ -3924,9 +3918,6 @@ impl Methods {
39243918 ( "is_digit" , [ radix] ) => is_digit_ascii_radix:: check ( cx, expr, recv, radix, & self . msrv ) ,
39253919 ( "is_none" , [ ] ) => check_is_some_is_none ( cx, expr, recv, false ) ,
39263920 ( "is_some" , [ ] ) => check_is_some_is_none ( cx, expr, recv, true ) ,
3927- ( "iter" | "iter_mut" | "into_iter" , [ ] ) => {
3928- iter_on_single_or_empty_collections:: check ( cx, expr, name, recv) ;
3929- } ,
39303921 ( "join" , [ join_arg] ) => {
39313922 if let Some ( ( "collect" , _, _, span, _) ) = method_call ( recv) {
39323923 unnecessary_join:: check ( cx, expr, recv, join_arg, span) ;
0 commit comments