@@ -1022,9 +1022,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
1022
1022
[ "flat_map" , "filter_map" ] => lint_filter_map_flat_map ( cx, expr, arg_lists[ 1 ] , arg_lists[ 0 ] ) ,
1023
1023
[ "flat_map" , ..] => lint_flat_map_identity ( cx, expr, arg_lists[ 0 ] , method_spans[ 0 ] ) ,
1024
1024
[ "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
+ } ,
1028
1032
[ "extend" , ..] => lint_extend ( cx, expr, arg_lists[ 0 ] ) ,
1029
1033
[ "as_ptr" , "unwrap" ] | [ "as_ptr" , "expect" ] => {
1030
1034
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>(
2381
2385
search_method : & str ,
2382
2386
search_args : & ' tcx [ hir:: Expr ] ,
2383
2387
is_some_args : & ' tcx [ hir:: Expr ] ,
2388
+ method_span : Span ,
2384
2389
) {
2385
2390
// lint if caller of search is an Iterator
2386
2391
if match_trait_method ( cx, & is_some_args[ 0 ] , & paths:: ITERATOR ) {
@@ -2398,15 +2403,13 @@ fn lint_search_is_some<'a, 'tcx>(
2398
2403
if let hir:: ExprKind :: Closure ( _, _, body_id, ..) = search_args[ 1 ] . node;
2399
2404
let closure_body = cx. tcx. hir( ) . body( body_id) ;
2400
2405
if let Some ( closure_arg) = closure_body. params. get( 0 ) ;
2401
- if let hir:: PatKind :: Ref ( ..) = closure_arg. pat. node;
2402
2406
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
2410
2413
}
2411
2414
} else {
2412
2415
None
@@ -2416,14 +2419,12 @@ fn lint_search_is_some<'a, 'tcx>(
2416
2419
span_lint_and_sugg (
2417
2420
cx,
2418
2421
SEARCH_IS_SOME ,
2419
- expr. span ,
2422
+ method_span . with_hi ( expr. span . hi ( ) ) ,
2420
2423
& msg,
2421
2424
"try this" ,
2422
2425
format ! (
2423
2426
"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)
2427
2428
) ,
2428
2429
Applicability :: MachineApplicable ,
2429
2430
) ;
0 commit comments