@@ -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;
@@ -2420,15 +2420,15 @@ declare_clippy_lint! {
2420
2420
2421
2421
declare_clippy_lint ! {
2422
2422
/// ### What it does
2423
- ///
2424
- /// Checks for calls to `iter`, `iter_mut` or `into_iter` on collections containing a single item
2423
+ /// Checks for calls to `iter`, `iter_mut` or `into_iter` on collections containing a single item.
2425
2424
///
2426
2425
/// ### Why is this bad?
2426
+ /// It is simpler to use the once function from the standard library.
2427
2427
///
2428
- /// It is simpler to use the once function from the standard library:
2428
+ /// ### Known problems
2429
+ /// The type of the resulting iterator might become incompatible with its usage.
2429
2430
///
2430
2431
/// ### Example
2431
- ///
2432
2432
/// ```rust
2433
2433
/// let a = [123].iter();
2434
2434
/// let b = Some(123).into_iter();
@@ -2439,27 +2439,23 @@ declare_clippy_lint! {
2439
2439
/// let a = iter::once(&123);
2440
2440
/// let b = iter::once(123);
2441
2441
/// ```
2442
- ///
2443
- /// ### Known problems
2444
- ///
2445
- /// The type of the resulting iterator might become incompatible with its usage
2446
2442
#[ clippy:: version = "1.65.0" ]
2447
2443
pub ITER_ON_SINGLE_ITEMS ,
2448
- nursery ,
2444
+ pedantic ,
2449
2445
"Iterator for array of length 1"
2450
2446
}
2451
2447
2452
2448
declare_clippy_lint ! {
2453
2449
/// ### What it does
2454
- ///
2455
- /// Checks for calls to `iter`, `iter_mut` or `into_iter` on empty collections
2450
+ /// Checks for calls to `iter`, `iter_mut` or `into_iter` on empty collections.
2456
2451
///
2457
2452
/// ### Why is this bad?
2453
+ /// It is simpler to use the empty function from the standard library.
2458
2454
///
2459
- /// It is simpler to use the empty function from the standard library:
2455
+ /// ### Known problems
2456
+ /// The type of the resulting iterator might become incompatible with its usage.
2460
2457
///
2461
2458
/// ### Example
2462
- ///
2463
2459
/// ```rust
2464
2460
/// use std::{slice, option};
2465
2461
/// let a: slice::Iter<i32> = [].iter();
@@ -2471,13 +2467,9 @@ declare_clippy_lint! {
2471
2467
/// let a: iter::Empty<i32> = iter::empty();
2472
2468
/// let b: iter::Empty<i32> = iter::empty();
2473
2469
/// ```
2474
- ///
2475
- /// ### Known problems
2476
- ///
2477
- /// The type of the resulting iterator might become incompatible with its usage
2478
2470
#[ clippy:: version = "1.65.0" ]
2479
2471
pub ITER_ON_EMPTY_COLLECTIONS ,
2480
- nursery ,
2472
+ pedantic ,
2481
2473
"Iterator for empty array"
2482
2474
}
2483
2475
@@ -3619,6 +3611,8 @@ fn method_call<'tcx>(
3619
3611
3620
3612
impl < ' tcx > LateLintPass < ' tcx > for Methods {
3621
3613
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx hir:: Expr < ' _ > ) {
3614
+ single_or_empty_collections_iter:: check ( cx, expr, & self . msrv ) ;
3615
+
3622
3616
if expr. span . from_expansion ( ) {
3623
3617
return ;
3624
3618
}
@@ -3916,9 +3910,6 @@ impl Methods {
3916
3910
( "is_digit" , [ radix] ) => is_digit_ascii_radix:: check ( cx, expr, recv, radix, & self . msrv ) ,
3917
3911
( "is_none" , [ ] ) => check_is_some_is_none ( cx, expr, recv, false ) ,
3918
3912
( "is_some" , [ ] ) => check_is_some_is_none ( cx, expr, recv, true ) ,
3919
- ( "iter" | "iter_mut" | "into_iter" , [ ] ) => {
3920
- iter_on_single_or_empty_collections:: check ( cx, expr, name, recv) ;
3921
- } ,
3922
3913
( "join" , [ join_arg] ) => {
3923
3914
if let Some ( ( "collect" , _, _, span, _) ) = method_call ( recv) {
3924
3915
unnecessary_join:: check ( cx, expr, recv, join_arg, span) ;
0 commit comments