@@ -302,6 +302,11 @@ declare_clippy_lint! {
302
302
/// # let vec = vec![1];
303
303
/// vec.iter().filter(|x| **x == 0).next();
304
304
/// ```
305
+ /// Could be written as
306
+ /// ```rust
307
+ /// # let vec = vec![1];
308
+ /// vec.iter().find(|x| **x == 0);
309
+ /// ```
305
310
pub FILTER_NEXT ,
306
311
complexity,
307
312
"using `filter(p).next()`, which is more succinctly expressed as `.find(p)`"
@@ -425,6 +430,11 @@ declare_clippy_lint! {
425
430
/// # let vec = vec![1];
426
431
/// vec.iter().find(|x| **x == 0).is_some();
427
432
/// ```
433
+ /// Could be written as
434
+ /// ```rust
435
+ /// # let vec = vec![1];
436
+ /// vec.iter().any(|x| *x == 0);
437
+ /// ```
428
438
pub SEARCH_IS_SOME ,
429
439
complexity,
430
440
"using an iterator search followed by `is_some()`, which is more succinctly expressed as a call to `any()`"
@@ -442,7 +452,12 @@ declare_clippy_lint! {
442
452
/// **Example:**
443
453
/// ```rust
444
454
/// let name = "foo";
445
- /// name.chars().next() == Some('_');
455
+ /// if name.chars().next() == Some('_') {};
456
+ /// ```
457
+ /// Could be written as
458
+ /// ```rust
459
+ /// let name = "foo";
460
+ /// if name.starts_with('_') {};
446
461
/// ```
447
462
pub CHARS_NEXT_CMP ,
448
463
complexity,
@@ -889,6 +904,10 @@ declare_clippy_lint! {
889
904
/// ```rust
890
905
/// let _ = [1, 2, 3].into_iter().map(|x| *x).collect::<Vec<u32>>();
891
906
/// ```
907
+ /// Could be written as:
908
+ /// ```rust
909
+ /// let _ = [1, 2, 3].iter().map(|x| *x).collect::<Vec<u32>>();
910
+ /// ```
892
911
pub INTO_ITER_ON_ARRAY ,
893
912
correctness,
894
913
"using `.into_iter()` on an array"
@@ -1713,8 +1732,8 @@ fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args:
1713
1732
if bin_op. node == op;
1714
1733
1715
1734
// Extract the names of the two arguments to the closure
1716
- if let Some ( first_arg_ident) = get_arg_name( & closure_body. arguments [ 0 ] . pat) ;
1717
- if let Some ( second_arg_ident) = get_arg_name( & closure_body. arguments [ 1 ] . pat) ;
1735
+ if let Some ( first_arg_ident) = get_arg_name( & closure_body. params [ 0 ] . pat) ;
1736
+ if let Some ( second_arg_ident) = get_arg_name( & closure_body. params [ 1 ] . pat) ;
1718
1737
1719
1738
if match_var( & * left_expr, first_arg_ident) ;
1720
1739
if replacement_has_args || match_var( & * right_expr, second_arg_ident) ;
@@ -2326,7 +2345,7 @@ fn lint_flat_map_identity<'a, 'tcx>(
2326
2345
if let hir:: ExprKind :: Closure ( _, _, body_id, _, _) = arg_node;
2327
2346
let body = cx. tcx. hir( ) . body( * body_id) ;
2328
2347
2329
- if let hir:: PatKind :: Binding ( _, _, binding_ident, _) = body. arguments [ 0 ] . pat. node;
2348
+ if let hir:: PatKind :: Binding ( _, _, binding_ident, _) = body. params [ 0 ] . pat. node;
2330
2349
if let hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, ref path) ) = body. value. node;
2331
2350
2332
2351
if path. segments. len( ) == 1 ;
@@ -2371,7 +2390,7 @@ fn lint_search_is_some<'a, 'tcx>(
2371
2390
if search_method == "find" ;
2372
2391
if let hir:: ExprKind :: Closure ( _, _, body_id, ..) = search_args[ 1 ] . node;
2373
2392
let closure_body = cx. tcx. hir( ) . body( body_id) ;
2374
- if let Some ( closure_arg) = closure_body. arguments . get( 0 ) ;
2393
+ if let Some ( closure_arg) = closure_body. params . get( 0 ) ;
2375
2394
if let hir:: PatKind :: Ref ( ..) = closure_arg. pat. node;
2376
2395
then {
2377
2396
Some ( search_snippet. replacen( '&' , "" , 1 ) )
@@ -2781,7 +2800,10 @@ impl SelfKind {
2781
2800
hir:: Mutability :: MutMutable => & paths:: ASMUT_TRAIT ,
2782
2801
} ;
2783
2802
2784
- let trait_def_id = get_trait_def_id ( cx, trait_path) . expect ( "trait def id not found" ) ;
2803
+ let trait_def_id = match get_trait_def_id ( cx, trait_path) {
2804
+ Some ( did) => did,
2805
+ None => return false ,
2806
+ } ;
2785
2807
implements_trait ( cx, ty, trait_def_id, & [ parent_ty. into ( ) ] )
2786
2808
}
2787
2809
0 commit comments