@@ -51,32 +51,28 @@ impl<'tcx> LateLintPass<'tcx> for IfLetMutex {
5151 if_else : Some ( if_else) ,
5252 ..
5353 } ) = higher:: IfLet :: hir ( cx, expr)
54+ && let Some ( op_mutex) = for_each_expr_without_closures ( let_expr, |e| mutex_lock_call ( cx, e, None ) )
55+ && let Some ( arm_mutex) =
56+ for_each_expr_without_closures ( ( if_then, if_else) , |e| mutex_lock_call ( cx, e, Some ( op_mutex) ) )
5457 {
55- let op_mutex = for_each_expr_without_closures ( let_expr, |e| mutex_lock_call ( cx, e, None ) ) ;
56- if let Some ( op_mutex) = op_mutex {
57- let arm_mutex =
58- for_each_expr_without_closures ( ( if_then, if_else) , |e| mutex_lock_call ( cx, e, Some ( op_mutex) ) ) ;
59- if let Some ( arm_mutex) = arm_mutex {
60- let diag = |diag : & mut Diag < ' _ , ( ) > | {
61- diag. span_label (
62- op_mutex. span ,
63- "this Mutex will remain locked for the entire `if let`-block..." ,
64- ) ;
65- diag. span_label (
66- arm_mutex. span ,
67- "... and is tried to lock again here, which will always deadlock." ,
68- ) ;
69- diag. help ( "move the lock call outside of the `if let ...` expression" ) ;
70- } ;
71- span_lint_and_then (
72- cx,
73- IF_LET_MUTEX ,
74- expr. span ,
75- "calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock" ,
76- diag,
77- ) ;
78- }
79- }
58+ let diag = |diag : & mut Diag < ' _ , ( ) > | {
59+ diag. span_label (
60+ op_mutex. span ,
61+ "this Mutex will remain locked for the entire `if let`-block..." ,
62+ ) ;
63+ diag. span_label (
64+ arm_mutex. span ,
65+ "... and is tried to lock again here, which will always deadlock." ,
66+ ) ;
67+ diag. help ( "move the lock call outside of the `if let ...` expression" ) ;
68+ } ;
69+ span_lint_and_then (
70+ cx,
71+ IF_LET_MUTEX ,
72+ expr. span ,
73+ "calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock" ,
74+ diag,
75+ ) ;
8076 }
8177 }
8278}
0 commit comments