@@ -41,7 +41,6 @@ mod iter_kv_map;
4141mod iter_next_slice;
4242mod iter_nth;
4343mod iter_nth_zero;
44- mod iter_on_single_or_empty_collections;
4544mod iter_overeager_cloned;
4645mod iter_skip_next;
4746mod iter_with_drain;
@@ -81,6 +80,7 @@ mod single_char_add_str;
8180mod single_char_insert_string;
8281mod single_char_pattern;
8382mod single_char_push_string;
83+ mod single_or_empty_collections_iter;
8484mod skip_while_next;
8585mod stable_sort_primitive;
8686mod str_splitn;
@@ -2417,15 +2417,15 @@ declare_clippy_lint! {
24172417
24182418declare_clippy_lint ! {
24192419 /// ### What it does
2420- ///
2421- /// Checks for calls to `iter`, `iter_mut` or `into_iter` on collections containing a single item
2420+ /// Checks for calls to `iter`, `iter_mut` or `into_iter` on collections containing a single item.
24222421 ///
24232422 /// ### Why is this bad?
2423+ /// It is simpler to use the once function from the standard library.
24242424 ///
2425- /// It is simpler to use the once function from the standard library:
2425+ /// ### Known problems
2426+ /// The type of the resulting iterator might become incompatible with its usage.
24262427 ///
24272428 /// ### Example
2428- ///
24292429 /// ```rust
24302430 /// let a = [123].iter();
24312431 /// let b = Some(123).into_iter();
@@ -2436,27 +2436,23 @@ declare_clippy_lint! {
24362436 /// let a = iter::once(&123);
24372437 /// let b = iter::once(123);
24382438 /// ```
2439- ///
2440- /// ### Known problems
2441- ///
2442- /// The type of the resulting iterator might become incompatible with its usage
24432439 #[ clippy:: version = "1.65.0" ]
24442440 pub ITER_ON_SINGLE_ITEMS ,
2445- nursery ,
2441+ pedantic ,
24462442 "Iterator for array of length 1"
24472443}
24482444
24492445declare_clippy_lint ! {
24502446 /// ### What it does
2451- ///
2452- /// Checks for calls to `iter`, `iter_mut` or `into_iter` on empty collections
2447+ /// Checks for calls to `iter`, `iter_mut` or `into_iter` on empty collections.
24532448 ///
24542449 /// ### Why is this bad?
2450+ /// It is simpler to use the empty function from the standard library.
24552451 ///
2456- /// It is simpler to use the empty function from the standard library:
2452+ /// ### Known problems
2453+ /// The type of the resulting iterator might become incompatible with its usage.
24572454 ///
24582455 /// ### Example
2459- ///
24602456 /// ```rust
24612457 /// use std::{slice, option};
24622458 /// let a: slice::Iter<i32> = [].iter();
@@ -2468,13 +2464,9 @@ declare_clippy_lint! {
24682464 /// let a: iter::Empty<i32> = iter::empty();
24692465 /// let b: iter::Empty<i32> = iter::empty();
24702466 /// ```
2471- ///
2472- /// ### Known problems
2473- ///
2474- /// The type of the resulting iterator might become incompatible with its usage
24752467 #[ clippy:: version = "1.65.0" ]
24762468 pub ITER_ON_EMPTY_COLLECTIONS ,
2477- nursery ,
2469+ pedantic ,
24782470 "Iterator for empty array"
24792471}
24802472
@@ -3529,6 +3521,8 @@ fn method_call<'tcx>(
35293521
35303522impl < ' tcx > LateLintPass < ' tcx > for Methods {
35313523 fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx hir:: Expr < ' _ > ) {
3524+ single_or_empty_collections_iter:: check ( cx, expr, & self . msrv ) ;
3525+
35323526 if expr. span . from_expansion ( ) {
35333527 return ;
35343528 }
@@ -3825,9 +3819,6 @@ impl Methods {
38253819 ( "is_digit" , [ radix] ) => is_digit_ascii_radix:: check ( cx, expr, recv, radix, & self . msrv ) ,
38263820 ( "is_none" , [ ] ) => check_is_some_is_none ( cx, expr, recv, false ) ,
38273821 ( "is_some" , [ ] ) => check_is_some_is_none ( cx, expr, recv, true ) ,
3828- ( "iter" | "iter_mut" | "into_iter" , [ ] ) => {
3829- iter_on_single_or_empty_collections:: check ( cx, expr, name, recv) ;
3830- } ,
38313822 ( "join" , [ join_arg] ) => {
38323823 if let Some ( ( "collect" , _, _, span, _) ) = method_call ( recv) {
38333824 unnecessary_join:: check ( cx, expr, recv, join_arg, span) ;
@@ -4204,7 +4195,7 @@ impl SelfKind {
42044195 } ;
42054196
42064197 let Some ( trait_def_id) = cx. tcx . get_diagnostic_item ( trait_sym) else {
4207- return false
4198+ return false ;
42084199 } ;
42094200 implements_trait ( cx, ty, trait_def_id, & [ parent_ty. into ( ) ] )
42104201 }
0 commit comments