@@ -41,7 +41,6 @@ mod iter_kv_map;
41
41
mod iter_next_slice;
42
42
mod iter_nth;
43
43
mod iter_nth_zero;
44
- mod iter_on_single_or_empty_collections;
45
44
mod iter_overeager_cloned;
46
45
mod iter_skip_next;
47
46
mod iter_with_drain;
@@ -81,6 +80,7 @@ mod single_char_add_str;
81
80
mod single_char_insert_string;
82
81
mod single_char_pattern;
83
82
mod single_char_push_string;
83
+ mod single_or_empty_collections_iter;
84
84
mod skip_while_next;
85
85
mod stable_sort_primitive;
86
86
mod str_splitn;
@@ -2417,15 +2417,15 @@ declare_clippy_lint! {
2417
2417
2418
2418
declare_clippy_lint ! {
2419
2419
/// ### 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.
2422
2421
///
2423
2422
/// ### Why is this bad?
2423
+ /// It is simpler to use the once function from the standard library.
2424
2424
///
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.
2426
2427
///
2427
2428
/// ### Example
2428
- ///
2429
2429
/// ```rust
2430
2430
/// let a = [123].iter();
2431
2431
/// let b = Some(123).into_iter();
@@ -2436,27 +2436,23 @@ declare_clippy_lint! {
2436
2436
/// let a = iter::once(&123);
2437
2437
/// let b = iter::once(123);
2438
2438
/// ```
2439
- ///
2440
- /// ### Known problems
2441
- ///
2442
- /// The type of the resulting iterator might become incompatible with its usage
2443
2439
#[ clippy:: version = "1.65.0" ]
2444
2440
pub ITER_ON_SINGLE_ITEMS ,
2445
- nursery ,
2441
+ pedantic ,
2446
2442
"Iterator for array of length 1"
2447
2443
}
2448
2444
2449
2445
declare_clippy_lint ! {
2450
2446
/// ### 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.
2453
2448
///
2454
2449
/// ### Why is this bad?
2450
+ /// It is simpler to use the empty function from the standard library.
2455
2451
///
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.
2457
2454
///
2458
2455
/// ### Example
2459
- ///
2460
2456
/// ```rust
2461
2457
/// use std::{slice, option};
2462
2458
/// let a: slice::Iter<i32> = [].iter();
@@ -2468,13 +2464,9 @@ declare_clippy_lint! {
2468
2464
/// let a: iter::Empty<i32> = iter::empty();
2469
2465
/// let b: iter::Empty<i32> = iter::empty();
2470
2466
/// ```
2471
- ///
2472
- /// ### Known problems
2473
- ///
2474
- /// The type of the resulting iterator might become incompatible with its usage
2475
2467
#[ clippy:: version = "1.65.0" ]
2476
2468
pub ITER_ON_EMPTY_COLLECTIONS ,
2477
- nursery ,
2469
+ pedantic ,
2478
2470
"Iterator for empty array"
2479
2471
}
2480
2472
@@ -3529,6 +3521,8 @@ fn method_call<'tcx>(
3529
3521
3530
3522
impl < ' tcx > LateLintPass < ' tcx > for Methods {
3531
3523
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx hir:: Expr < ' _ > ) {
3524
+ single_or_empty_collections_iter:: check ( cx, expr, & self . msrv ) ;
3525
+
3532
3526
if expr. span . from_expansion ( ) {
3533
3527
return ;
3534
3528
}
@@ -3825,9 +3819,6 @@ impl Methods {
3825
3819
( "is_digit" , [ radix] ) => is_digit_ascii_radix:: check ( cx, expr, recv, radix, & self . msrv ) ,
3826
3820
( "is_none" , [ ] ) => check_is_some_is_none ( cx, expr, recv, false ) ,
3827
3821
( "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
- } ,
3831
3822
( "join" , [ join_arg] ) => {
3832
3823
if let Some ( ( "collect" , _, _, span, _) ) = method_call ( recv) {
3833
3824
unnecessary_join:: check ( cx, expr, recv, join_arg, span) ;
@@ -4204,7 +4195,7 @@ impl SelfKind {
4204
4195
} ;
4205
4196
4206
4197
let Some ( trait_def_id) = cx. tcx . get_diagnostic_item ( trait_sym) else {
4207
- return false
4198
+ return false ;
4208
4199
} ;
4209
4200
implements_trait ( cx, ty, trait_def_id, & [ parent_ty. into ( ) ] )
4210
4201
}
0 commit comments