@@ -43,7 +43,6 @@ mod iter_kv_map;
43
43
mod iter_next_slice;
44
44
mod iter_nth;
45
45
mod iter_nth_zero;
46
- mod iter_on_single_or_empty_collections;
47
46
mod iter_overeager_cloned;
48
47
mod iter_skip_next;
49
48
mod iter_skip_zero;
@@ -85,6 +84,7 @@ mod single_char_add_str;
85
84
mod single_char_insert_string;
86
85
mod single_char_pattern;
87
86
mod single_char_push_string;
87
+ mod single_or_empty_collections_iter;
88
88
mod skip_while_next;
89
89
mod stable_sort_primitive;
90
90
mod str_splitn;
@@ -2432,15 +2432,15 @@ declare_clippy_lint! {
2432
2432
2433
2433
declare_clippy_lint ! {
2434
2434
/// ### 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.
2437
2436
///
2438
2437
/// ### Why is this bad?
2438
+ /// It is simpler to use the once function from the standard library.
2439
2439
///
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.
2441
2442
///
2442
2443
/// ### Example
2443
- ///
2444
2444
/// ```rust
2445
2445
/// let a = [123].iter();
2446
2446
/// let b = Some(123).into_iter();
@@ -2451,27 +2451,23 @@ declare_clippy_lint! {
2451
2451
/// let a = iter::once(&123);
2452
2452
/// let b = iter::once(123);
2453
2453
/// ```
2454
- ///
2455
- /// ### Known problems
2456
- ///
2457
- /// The type of the resulting iterator might become incompatible with its usage
2458
2454
#[ clippy:: version = "1.65.0" ]
2459
2455
pub ITER_ON_SINGLE_ITEMS ,
2460
- nursery ,
2456
+ pedantic ,
2461
2457
"Iterator for array of length 1"
2462
2458
}
2463
2459
2464
2460
declare_clippy_lint ! {
2465
2461
/// ### 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.
2468
2463
///
2469
2464
/// ### Why is this bad?
2465
+ /// It is simpler to use the empty function from the standard library.
2470
2466
///
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.
2472
2469
///
2473
2470
/// ### Example
2474
- ///
2475
2471
/// ```rust
2476
2472
/// use std::{slice, option};
2477
2473
/// let a: slice::Iter<i32> = [].iter();
@@ -2483,13 +2479,9 @@ declare_clippy_lint! {
2483
2479
/// let a: iter::Empty<i32> = iter::empty();
2484
2480
/// let b: iter::Empty<i32> = iter::empty();
2485
2481
/// ```
2486
- ///
2487
- /// ### Known problems
2488
- ///
2489
- /// The type of the resulting iterator might become incompatible with its usage
2490
2482
#[ clippy:: version = "1.65.0" ]
2491
2483
pub ITER_ON_EMPTY_COLLECTIONS ,
2492
- nursery ,
2484
+ pedantic ,
2493
2485
"Iterator for empty array"
2494
2486
}
2495
2487
@@ -3695,6 +3687,8 @@ fn method_call<'tcx>(
3695
3687
3696
3688
impl < ' tcx > LateLintPass < ' tcx > for Methods {
3697
3689
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx hir:: Expr < ' _ > ) {
3690
+ single_or_empty_collections_iter:: check ( cx, expr, & self . msrv ) ;
3691
+
3698
3692
if expr. span . from_expansion ( ) {
3699
3693
return ;
3700
3694
}
@@ -3991,9 +3985,6 @@ impl Methods {
3991
3985
( "is_digit" , [ radix] ) => is_digit_ascii_radix:: check ( cx, expr, recv, radix, & self . msrv ) ,
3992
3986
( "is_none" , [ ] ) => check_is_some_is_none ( cx, expr, recv, false ) ,
3993
3987
( "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
- } ,
3997
3988
( "join" , [ join_arg] ) => {
3998
3989
if let Some ( ( "collect" , _, _, span, _) ) = method_call ( recv) {
3999
3990
unnecessary_join:: check ( cx, expr, recv, join_arg, span) ;
0 commit comments