@@ -1022,9 +1022,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
10221022 [ "flat_map" , "filter_map" ] => lint_filter_map_flat_map ( cx, expr, arg_lists[ 1 ] , arg_lists[ 0 ] ) ,
10231023 [ "flat_map" , ..] => lint_flat_map_identity ( cx, expr, arg_lists[ 0 ] , method_spans[ 0 ] ) ,
10241024 [ "flatten" , "map" ] => lint_map_flatten ( cx, expr, arg_lists[ 1 ] ) ,
1025- [ "is_some" , "find" ] => lint_search_is_some ( cx, expr, "find" , arg_lists[ 1 ] , arg_lists[ 0 ] ) ,
1026- [ "is_some" , "position" ] => lint_search_is_some ( cx, expr, "position" , arg_lists[ 1 ] , arg_lists[ 0 ] ) ,
1027- [ "is_some" , "rposition" ] => lint_search_is_some ( cx, expr, "rposition" , arg_lists[ 1 ] , arg_lists[ 0 ] ) ,
1025+ [ "is_some" , "find" ] => lint_search_is_some ( cx, expr, "find" , arg_lists[ 1 ] , arg_lists[ 0 ] , method_spans[ 1 ] ) ,
1026+ [ "is_some" , "position" ] => {
1027+ lint_search_is_some ( cx, expr, "position" , arg_lists[ 1 ] , arg_lists[ 0 ] , method_spans[ 1 ] )
1028+ } ,
1029+ [ "is_some" , "rposition" ] => {
1030+ lint_search_is_some ( cx, expr, "rposition" , arg_lists[ 1 ] , arg_lists[ 0 ] , method_spans[ 1 ] )
1031+ } ,
10281032 [ "extend" , ..] => lint_extend ( cx, expr, arg_lists[ 0 ] ) ,
10291033 [ "as_ptr" , "unwrap" ] | [ "as_ptr" , "expect" ] => {
10301034 lint_cstring_as_ptr ( cx, expr, & arg_lists[ 1 ] [ 0 ] , & arg_lists[ 0 ] [ 0 ] )
@@ -2381,6 +2385,7 @@ fn lint_search_is_some<'a, 'tcx>(
23812385 search_method : & str ,
23822386 search_args : & ' tcx [ hir:: Expr ] ,
23832387 is_some_args : & ' tcx [ hir:: Expr ] ,
2388+ method_span : Span ,
23842389) {
23852390 // lint if caller of search is an Iterator
23862391 if match_trait_method ( cx, & is_some_args[ 0 ] , & paths:: ITERATOR ) {
@@ -2398,15 +2403,13 @@ fn lint_search_is_some<'a, 'tcx>(
23982403 if let hir:: ExprKind :: Closure ( _, _, body_id, ..) = search_args[ 1 ] . node;
23992404 let closure_body = cx. tcx. hir( ) . body( body_id) ;
24002405 if let Some ( closure_arg) = closure_body. params. get( 0 ) ;
2401- if let hir:: PatKind :: Ref ( ..) = closure_arg. pat. node;
24022406 then {
2403- match & closure_arg. pat. node {
2404- hir:: PatKind :: Ref ( ..) => Some ( search_snippet. replacen( '&' , "" , 1 ) ) ,
2405- hir:: PatKind :: Binding ( _, _, expr, _) => {
2406- let closure_arg_snip = snippet( cx, expr. span, ".." ) ;
2407- Some ( search_snippet. replace( & format!( "*{}" , closure_arg_snip) , & closure_arg_snip) )
2408- }
2409- _ => None ,
2407+ if let hir:: PatKind :: Ref ( ..) = closure_arg. pat. node {
2408+ Some ( search_snippet. replacen( '&' , "" , 1 ) )
2409+ } else if let Some ( name) = get_arg_name( & closure_arg. pat) {
2410+ Some ( search_snippet. replace( & format!( "*{}" , name) , & name. as_str( ) ) )
2411+ } else {
2412+ None
24102413 }
24112414 } else {
24122415 None
@@ -2416,14 +2419,12 @@ fn lint_search_is_some<'a, 'tcx>(
24162419 span_lint_and_sugg (
24172420 cx,
24182421 SEARCH_IS_SOME ,
2419- expr. span ,
2422+ method_span . with_hi ( expr. span . hi ( ) ) ,
24202423 & msg,
24212424 "try this" ,
24222425 format ! (
24232426 "any({})" ,
2424- any_search_snippet
2425- . as_ref( )
2426- . map_or( & * search_snippet, String :: as_str)
2427+ any_search_snippet. as_ref( ) . map_or( & * search_snippet, String :: as_str)
24272428 ) ,
24282429 Applicability :: MachineApplicable ,
24292430 ) ;
0 commit comments