@@ -65,27 +65,29 @@ impl LateLintPass<'_> for LinesFilterMapOk {
6565 matches ! ( fm_method_str, "filter_map" | "flat_map" | "flatten" ) &&
6666 is_type_diagnostic_item ( cx, cx. typeck_results ( ) . expr_ty_adjusted ( fm_receiver) , sym:: IoLines )
6767 {
68- let lint = if let [ fm_arg] = fm_args {
69- match & fm_arg. kind {
70- // Detect `Result::ok`
71- ExprKind :: Path ( qpath) =>
72- cx. qpath_res ( qpath, fm_arg. hir_id ) . opt_def_id ( ) . map ( |did|
73- match_def_path ( cx, did, & paths:: CORE_RESULT_OK_METHOD ) ) . unwrap_or_default ( ) ,
74- // Detect `|x| x.ok()`
75- ExprKind :: Closure ( Closure { body, .. } ) =>
76- if let Body { params : [ param] , value, .. } = cx. tcx . hir ( ) . body ( * body) &&
77- let ExprKind :: MethodCall ( method, receiver, [ ] , _) = value. kind &&
78- path_to_local_id ( receiver, param. pat . hir_id ) &&
79- let Some ( method_did) = cx. typeck_results ( ) . type_dependent_def_id ( value. hir_id )
80- {
81- is_diag_item_method ( cx, method_did, sym:: Result ) && method. ident . as_str ( ) == "ok"
82- } else {
83- false
84- } ,
85- _ => false ,
68+ let lint = match fm_args {
69+ [ ] => fm_method_str == "flatten" ,
70+ [ fm_arg] => {
71+ match & fm_arg. kind {
72+ // Detect `Result::ok`
73+ ExprKind :: Path ( qpath) =>
74+ cx. qpath_res ( qpath, fm_arg. hir_id ) . opt_def_id ( ) . map ( |did|
75+ match_def_path ( cx, did, & paths:: CORE_RESULT_OK_METHOD ) ) . unwrap_or_default ( ) ,
76+ // Detect `|x| x.ok()`
77+ ExprKind :: Closure ( Closure { body, .. } ) =>
78+ if let Body { params : [ param] , value, .. } = cx. tcx . hir ( ) . body ( * body) &&
79+ let ExprKind :: MethodCall ( method, receiver, [ ] , _) = value. kind &&
80+ path_to_local_id ( receiver, param. pat . hir_id ) &&
81+ let Some ( method_did) = cx. typeck_results ( ) . type_dependent_def_id ( value. hir_id )
82+ {
83+ is_diag_item_method ( cx, method_did, sym:: Result ) && method. ident . as_str ( ) == "ok"
84+ } else {
85+ false
86+ } ,
87+ _ => false ,
88+ }
8689 }
87- } else {
88- fm_method_str == "flatten"
90+ _ => false ,
8991 } ;
9092
9193 if lint {
0 commit comments