@@ -43,7 +43,6 @@ mod iter_kv_map;
4343mod iter_next_slice;
4444mod iter_nth;
4545mod iter_nth_zero;
46- mod iter_on_single_or_empty_collections;
4746mod iter_overeager_cloned;
4847mod iter_skip_next;
4948mod iter_skip_zero;
@@ -85,6 +84,7 @@ mod single_char_add_str;
8584mod single_char_insert_string;
8685mod single_char_pattern;
8786mod single_char_push_string;
87+ mod single_or_empty_collections_iter;
8888mod skip_while_next;
8989mod stable_sort_primitive;
9090mod str_splitn;
@@ -2432,15 +2432,15 @@ declare_clippy_lint! {
24322432
24332433declare_clippy_lint ! {
24342434 /// ### What it does
2435- ///
2436- /// Checks for calls to `iter`, `iter_mut` or `into_iter` on collections containing a single item
2435+ /// Checks for calls to `iter`, `iter_mut` or `into_iter` on collections containing a single item.
24372436 ///
24382437 /// ### Why is this bad?
2438+ /// It is simpler to use the once function from the standard library.
24392439 ///
2440- /// It is simpler to use the once function from the standard library:
2440+ /// ### Known problems
2441+ /// The type of the resulting iterator might become incompatible with its usage.
24412442 ///
24422443 /// ### Example
2443- ///
24442444 /// ```rust
24452445 /// let a = [123].iter();
24462446 /// let b = Some(123).into_iter();
@@ -2451,27 +2451,23 @@ declare_clippy_lint! {
24512451 /// let a = iter::once(&123);
24522452 /// let b = iter::once(123);
24532453 /// ```
2454- ///
2455- /// ### Known problems
2456- ///
2457- /// The type of the resulting iterator might become incompatible with its usage
24582454 #[ clippy:: version = "1.65.0" ]
24592455 pub ITER_ON_SINGLE_ITEMS ,
2460- nursery ,
2456+ pedantic ,
24612457 "Iterator for array of length 1"
24622458}
24632459
24642460declare_clippy_lint ! {
24652461 /// ### What it does
2466- ///
2467- /// Checks for calls to `iter`, `iter_mut` or `into_iter` on empty collections
2462+ /// Checks for calls to `iter`, `iter_mut` or `into_iter` on empty collections.
24682463 ///
24692464 /// ### Why is this bad?
2465+ /// It is simpler to use the empty function from the standard library.
24702466 ///
2471- /// It is simpler to use the empty function from the standard library:
2467+ /// ### Known problems
2468+ /// The type of the resulting iterator might become incompatible with its usage.
24722469 ///
24732470 /// ### Example
2474- ///
24752471 /// ```rust
24762472 /// use std::{slice, option};
24772473 /// let a: slice::Iter<i32> = [].iter();
@@ -2483,13 +2479,9 @@ declare_clippy_lint! {
24832479 /// let a: iter::Empty<i32> = iter::empty();
24842480 /// let b: iter::Empty<i32> = iter::empty();
24852481 /// ```
2486- ///
2487- /// ### Known problems
2488- ///
2489- /// The type of the resulting iterator might become incompatible with its usage
24902482 #[ clippy:: version = "1.65.0" ]
24912483 pub ITER_ON_EMPTY_COLLECTIONS ,
2492- nursery ,
2484+ pedantic ,
24932485 "Iterator for empty array"
24942486}
24952487
@@ -3695,6 +3687,8 @@ fn method_call<'tcx>(
36953687
36963688impl < ' tcx > LateLintPass < ' tcx > for Methods {
36973689 fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx hir:: Expr < ' _ > ) {
3690+ single_or_empty_collections_iter:: check ( cx, expr, & self . msrv ) ;
3691+
36983692 if expr. span . from_expansion ( ) {
36993693 return ;
37003694 }
@@ -3991,9 +3985,6 @@ impl Methods {
39913985 ( "is_digit" , [ radix] ) => is_digit_ascii_radix:: check ( cx, expr, recv, radix, & self . msrv ) ,
39923986 ( "is_none" , [ ] ) => check_is_some_is_none ( cx, expr, recv, false ) ,
39933987 ( "is_some" , [ ] ) => check_is_some_is_none ( cx, expr, recv, true ) ,
3994- ( "iter" | "iter_mut" | "into_iter" , [ ] ) => {
3995- iter_on_single_or_empty_collections:: check ( cx, expr, name, recv) ;
3996- } ,
39973988 ( "join" , [ join_arg] ) => {
39983989 if let Some ( ( "collect" , _, _, span, _) ) = method_call ( recv) {
39993990 unnecessary_join:: check ( cx, expr, recv, join_arg, span) ;
0 commit comments