@@ -1803,6 +1803,14 @@ fn lint_or_fun_call<'tcx>(
1803
1803
or_has_args : bool ,
1804
1804
span : Span ,
1805
1805
) {
1806
+ // (path, fn_has_argument, methods, suffix)
1807
+ static KNOW_TYPES : [ ( & [ & str ] , bool , & [ & str ] , & str ) ; 4 ] = [
1808
+ ( & paths:: BTREEMAP_ENTRY , false , & [ "or_insert" ] , "with" ) ,
1809
+ ( & paths:: HASHMAP_ENTRY , false , & [ "or_insert" ] , "with" ) ,
1810
+ ( & paths:: OPTION , false , & [ "map_or" , "ok_or" , "or" , "unwrap_or" ] , "else" ) ,
1811
+ ( & paths:: RESULT , true , & [ "or" , "unwrap_or" ] , "else" ) ,
1812
+ ] ;
1813
+
1806
1814
if let hir:: ExprKind :: MethodCall ( ref path, _, ref args, _) = & arg. kind {
1807
1815
if path. ident . as_str ( ) == "len" {
1808
1816
let ty = cx. typeck_results ( ) . expr_ty ( & args[ 0 ] ) . peel_refs ( ) ;
@@ -1818,24 +1826,16 @@ fn lint_or_fun_call<'tcx>(
1818
1826
}
1819
1827
}
1820
1828
1821
- // (path, fn_has_argument, methods, suffix)
1822
- let know_types: & [ ( & [ _ ] , _ , & [ _ ] , _ ) ] = & [
1823
- ( & paths:: BTREEMAP_ENTRY , false , & [ "or_insert" ] , "with" ) ,
1824
- ( & paths:: HASHMAP_ENTRY , false , & [ "or_insert" ] , "with" ) ,
1825
- ( & paths:: OPTION , false , & [ "map_or" , "ok_or" , "or" , "unwrap_or" ] , "else" ) ,
1826
- ( & paths:: RESULT , true , & [ "or" , "unwrap_or" ] , "else" ) ,
1827
- ] ;
1828
-
1829
1829
if_chain ! {
1830
- if know_types . iter( ) . any( |k| k. 2 . contains( & name) ) ;
1830
+ if KNOW_TYPES . iter( ) . any( |k| k. 2 . contains( & name) ) ;
1831
1831
1832
1832
if is_lazyness_candidate( cx, arg) ;
1833
1833
if !contains_return( & arg) ;
1834
1834
1835
1835
let self_ty = cx. typeck_results( ) . expr_ty( self_expr) ;
1836
1836
1837
1837
if let Some ( & ( _, fn_has_arguments, poss, suffix) ) =
1838
- know_types . iter( ) . find( |&&i| match_type( cx, self_ty, i. 0 ) ) ;
1838
+ KNOW_TYPES . iter( ) . find( |&&i| match_type( cx, self_ty, i. 0 ) ) ;
1839
1839
1840
1840
if poss. contains( & name) ;
1841
1841
0 commit comments