@@ -42,7 +42,6 @@ mod iter_kv_map;
42
42
mod iter_next_slice;
43
43
mod iter_nth;
44
44
mod iter_nth_zero;
45
- mod iter_on_single_or_empty_collections;
46
45
mod iter_overeager_cloned;
47
46
mod iter_skip_next;
48
47
mod iter_skip_zero;
@@ -83,6 +82,7 @@ mod single_char_add_str;
83
82
mod single_char_insert_string;
84
83
mod single_char_pattern;
85
84
mod single_char_push_string;
85
+ mod single_or_empty_collections_iter;
86
86
mod skip_while_next;
87
87
mod stable_sort_primitive;
88
88
mod str_splitn;
@@ -2430,15 +2430,15 @@ declare_clippy_lint! {
2430
2430
2431
2431
declare_clippy_lint ! {
2432
2432
/// ### 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.
2435
2434
///
2436
2435
/// ### Why is this bad?
2436
+ /// It is simpler to use the once function from the standard library.
2437
2437
///
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.
2439
2440
///
2440
2441
/// ### Example
2441
- ///
2442
2442
/// ```rust
2443
2443
/// let a = [123].iter();
2444
2444
/// let b = Some(123).into_iter();
@@ -2449,27 +2449,23 @@ declare_clippy_lint! {
2449
2449
/// let a = iter::once(&123);
2450
2450
/// let b = iter::once(123);
2451
2451
/// ```
2452
- ///
2453
- /// ### Known problems
2454
- ///
2455
- /// The type of the resulting iterator might become incompatible with its usage
2456
2452
#[ clippy:: version = "1.65.0" ]
2457
2453
pub ITER_ON_SINGLE_ITEMS ,
2458
- nursery ,
2454
+ pedantic ,
2459
2455
"Iterator for array of length 1"
2460
2456
}
2461
2457
2462
2458
declare_clippy_lint ! {
2463
2459
/// ### 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.
2466
2461
///
2467
2462
/// ### Why is this bad?
2463
+ /// It is simpler to use the empty function from the standard library.
2468
2464
///
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.
2470
2467
///
2471
2468
/// ### Example
2472
- ///
2473
2469
/// ```rust
2474
2470
/// use std::{slice, option};
2475
2471
/// let a: slice::Iter<i32> = [].iter();
@@ -2481,13 +2477,9 @@ declare_clippy_lint! {
2481
2477
/// let a: iter::Empty<i32> = iter::empty();
2482
2478
/// let b: iter::Empty<i32> = iter::empty();
2483
2479
/// ```
2484
- ///
2485
- /// ### Known problems
2486
- ///
2487
- /// The type of the resulting iterator might become incompatible with its usage
2488
2480
#[ clippy:: version = "1.65.0" ]
2489
2481
pub ITER_ON_EMPTY_COLLECTIONS ,
2490
- nursery ,
2482
+ pedantic ,
2491
2483
"Iterator for empty array"
2492
2484
}
2493
2485
@@ -3629,6 +3621,8 @@ fn method_call<'tcx>(
3629
3621
3630
3622
impl < ' tcx > LateLintPass < ' tcx > for Methods {
3631
3623
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx hir:: Expr < ' _ > ) {
3624
+ single_or_empty_collections_iter:: check ( cx, expr, & self . msrv ) ;
3625
+
3632
3626
if expr. span . from_expansion ( ) {
3633
3627
return ;
3634
3628
}
@@ -3924,9 +3918,6 @@ impl Methods {
3924
3918
( "is_digit" , [ radix] ) => is_digit_ascii_radix:: check ( cx, expr, recv, radix, & self . msrv ) ,
3925
3919
( "is_none" , [ ] ) => check_is_some_is_none ( cx, expr, recv, false ) ,
3926
3920
( "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
- } ,
3930
3921
( "join" , [ join_arg] ) => {
3931
3922
if let Some ( ( "collect" , _, _, span, _) ) = method_call ( recv) {
3932
3923
unnecessary_join:: check ( cx, expr, recv, join_arg, span) ;
0 commit comments