@@ -1797,11 +1797,11 @@ fn lint_or_fun_call<'tcx>(
1797
1797
cx : & LateContext < ' tcx > ,
1798
1798
name : & str ,
1799
1799
method_span : Span ,
1800
- fun_span : Span ,
1801
1800
self_expr : & hir:: Expr < ' _ > ,
1802
1801
arg : & ' tcx hir:: Expr < ' _ > ,
1803
- or_has_args : bool ,
1804
1802
span : Span ,
1803
+ // None if lambda is required
1804
+ fun_span : Option < Span > ,
1805
1805
) {
1806
1806
// (path, fn_has_argument, methods, suffix)
1807
1807
static KNOW_TYPES : [ ( & [ & str ] , bool , & [ & str ] , & str ) ; 4 ] = [
@@ -1840,10 +1840,18 @@ fn lint_or_fun_call<'tcx>(
1840
1840
if poss. contains( & name) ;
1841
1841
1842
1842
then {
1843
- let sugg: Cow <' _, _> = match ( fn_has_arguments, !or_has_args) {
1844
- ( true , _) => format!( "|_| {}" , snippet_with_macro_callsite( cx, arg. span, ".." ) ) . into( ) ,
1845
- ( false , false ) => format!( "|| {}" , snippet_with_macro_callsite( cx, arg. span, ".." ) ) . into( ) ,
1846
- ( false , true ) => snippet_with_macro_callsite( cx, fun_span, ".." ) ,
1843
+ let sugg: Cow <' _, str > = {
1844
+ let ( snippet_span, use_lambda) = match ( fn_has_arguments, fun_span) {
1845
+ ( false , Some ( fun_span) ) => ( fun_span, false ) ,
1846
+ _ => ( arg. span, true ) ,
1847
+ } ;
1848
+ let snippet = snippet_with_macro_callsite( cx, snippet_span, ".." ) ;
1849
+ if use_lambda {
1850
+ let l_arg = if fn_has_arguments { "_" } else { "" } ;
1851
+ format!( "|{}| {}" , l_arg, snippet) . into( )
1852
+ } else {
1853
+ snippet
1854
+ }
1847
1855
} ;
1848
1856
let span_replace_word = method_span. with_hi( span. hi( ) ) ;
1849
1857
span_lint_and_sugg(
@@ -1864,28 +1872,13 @@ fn lint_or_fun_call<'tcx>(
1864
1872
hir:: ExprKind :: Call ( ref fun, ref or_args) => {
1865
1873
let or_has_args = !or_args. is_empty ( ) ;
1866
1874
if !check_unwrap_or_default ( cx, name, fun, & args[ 0 ] , & args[ 1 ] , or_has_args, expr. span ) {
1867
- check_general_case (
1868
- cx,
1869
- name,
1870
- method_span,
1871
- fun. span ,
1872
- & args[ 0 ] ,
1873
- & args[ 1 ] ,
1874
- or_has_args,
1875
- expr. span ,
1876
- ) ;
1875
+ let fun_span = if or_has_args { None } else { Some ( fun. span ) } ;
1876
+ check_general_case ( cx, name, method_span, & args[ 0 ] , & args[ 1 ] , expr. span , fun_span) ;
1877
1877
}
1878
1878
} ,
1879
- hir:: ExprKind :: MethodCall ( _, span, ref or_args, _) => check_general_case (
1880
- cx,
1881
- name,
1882
- method_span,
1883
- span,
1884
- & args[ 0 ] ,
1885
- & args[ 1 ] ,
1886
- !or_args. is_empty ( ) ,
1887
- expr. span ,
1888
- ) ,
1879
+ hir:: ExprKind :: Index ( ..) | hir:: ExprKind :: MethodCall ( ..) => {
1880
+ check_general_case ( cx, name, method_span, & args[ 0 ] , & args[ 1 ] , expr. span , None ) ;
1881
+ } ,
1889
1882
_ => { } ,
1890
1883
}
1891
1884
}
0 commit comments