@@ -302,6 +302,11 @@ declare_clippy_lint! {
302302 /// # let vec = vec![1];
303303 /// vec.iter().filter(|x| **x == 0).next();
304304 /// ```
305+ /// Could be written as
306+ /// ```rust
307+ /// # let vec = vec![1];
308+ /// vec.iter().find(|x| **x == 0);
309+ /// ```
305310 pub FILTER_NEXT ,
306311 complexity,
307312 "using `filter(p).next()`, which is more succinctly expressed as `.find(p)`"
@@ -425,6 +430,11 @@ declare_clippy_lint! {
425430 /// # let vec = vec![1];
426431 /// vec.iter().find(|x| **x == 0).is_some();
427432 /// ```
433+ /// Could be written as
434+ /// ```rust
435+ /// # let vec = vec![1];
436+ /// vec.iter().any(|x| *x == 0);
437+ /// ```
428438 pub SEARCH_IS_SOME ,
429439 complexity,
430440 "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! {
442452 /// **Example:**
443453 /// ```rust
444454 /// 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('_') {};
446461 /// ```
447462 pub CHARS_NEXT_CMP ,
448463 complexity,
@@ -889,6 +904,10 @@ declare_clippy_lint! {
889904 /// ```rust
890905 /// let _ = [1, 2, 3].into_iter().map(|x| *x).collect::<Vec<u32>>();
891906 /// ```
907+ /// Could be written as:
908+ /// ```rust
909+ /// let _ = [1, 2, 3].iter().map(|x| *x).collect::<Vec<u32>>();
910+ /// ```
892911 pub INTO_ITER_ON_ARRAY ,
893912 correctness,
894913 "using `.into_iter()` on an array"
@@ -1713,8 +1732,8 @@ fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args:
17131732 if bin_op. node == op;
17141733
17151734 // 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) ;
17181737
17191738 if match_var( & * left_expr, first_arg_ident) ;
17201739 if replacement_has_args || match_var( & * right_expr, second_arg_ident) ;
@@ -2326,7 +2345,7 @@ fn lint_flat_map_identity<'a, 'tcx>(
23262345 if let hir:: ExprKind :: Closure ( _, _, body_id, _, _) = arg_node;
23272346 let body = cx. tcx. hir( ) . body( * body_id) ;
23282347
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;
23302349 if let hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, ref path) ) = body. value. node;
23312350
23322351 if path. segments. len( ) == 1 ;
@@ -2371,7 +2390,7 @@ fn lint_search_is_some<'a, 'tcx>(
23712390 if search_method == "find" ;
23722391 if let hir:: ExprKind :: Closure ( _, _, body_id, ..) = search_args[ 1 ] . node;
23732392 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 ) ;
23752394 if let hir:: PatKind :: Ref ( ..) = closure_arg. pat. node;
23762395 then {
23772396 Some ( search_snippet. replacen( '&' , "" , 1 ) )
@@ -2781,7 +2800,10 @@ impl SelfKind {
27812800 hir:: Mutability :: MutMutable => & paths:: ASMUT_TRAIT ,
27822801 } ;
27832802
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+ } ;
27852807 implements_trait ( cx, ty, trait_def_id, & [ parent_ty. into ( ) ] )
27862808 }
27872809
0 commit comments