@@ -45,21 +45,23 @@ declare_lint_pass!(IfLetMutex => [IF_LET_MUTEX]);
45
45
46
46
impl < ' tcx > LateLintPass < ' tcx > for IfLetMutex {
47
47
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' tcx > ) {
48
- let mut arm_visit = ArmVisitor { found_mutex : None , cx } ;
49
- let mut op_visit = OppVisitor { found_mutex : None , cx } ;
48
+ let mut arm_visit = ArmVisitor { cx } ;
49
+ let mut op_visit = OppVisitor { cx } ;
50
50
if let Some ( higher:: IfLet {
51
51
let_expr,
52
52
if_then,
53
53
if_else : Some ( if_else) ,
54
54
..
55
55
} ) = higher:: IfLet :: hir ( cx, expr)
56
56
{
57
- op_visit. visit_expr ( let_expr) ;
58
- if let Some ( op_mutex) = op_visit. found_mutex {
59
- arm_visit. visit_expr ( if_then) ;
60
- arm_visit. visit_expr ( if_else) ;
57
+ let found_op_mutex = op_visit. visit_expr ( let_expr) . break_value ( ) ;
58
+ if let Some ( op_mutex) = found_op_mutex {
59
+ let mut found_mutex = arm_visit. visit_expr ( if_then) . break_value ( ) ;
60
+ if found_mutex. is_none ( ) {
61
+ found_mutex = arm_visit. visit_expr ( if_else) . break_value ( ) ;
62
+ } ;
61
63
62
- if let Some ( arm_mutex) = arm_visit. found_mutex_if_same_as ( op_mutex) {
64
+ if let Some ( arm_mutex) = arm_visit. found_mutex_if_same_as ( op_mutex, found_mutex ) {
63
65
let diag = |diag : & mut Diag < ' _ , ( ) > | {
64
66
diag. span_label (
65
67
op_mutex. span ,
@@ -86,43 +88,37 @@ impl<'tcx> LateLintPass<'tcx> for IfLetMutex {
86
88
87
89
/// Checks if `Mutex::lock` is called in the `if let` expr.
88
90
pub struct OppVisitor < ' a , ' tcx > {
89
- found_mutex : Option < & ' tcx Expr < ' tcx > > ,
90
91
cx : & ' a LateContext < ' tcx > ,
91
92
}
92
93
93
94
impl < ' tcx > Visitor < ' tcx > for OppVisitor < ' _ , ' tcx > {
94
- type Result = ControlFlow < ( ) > ;
95
- fn visit_expr ( & mut self , expr : & ' tcx Expr < ' _ > ) -> ControlFlow < ( ) > {
95
+ type Result = ControlFlow < & ' tcx Expr < ' tcx > > ;
96
+ fn visit_expr ( & mut self , expr : & ' tcx Expr < ' _ > ) -> ControlFlow < & ' tcx Expr < ' tcx > > {
96
97
if let Some ( mutex) = is_mutex_lock_call ( self . cx , expr) {
97
- self . found_mutex = Some ( mutex) ;
98
- return ControlFlow :: Break ( ( ) ) ;
98
+ return ControlFlow :: Break ( mutex) ;
99
99
}
100
- visit:: walk_expr ( self , expr) ;
101
- ControlFlow :: Continue ( ( ) )
100
+ visit:: walk_expr ( self , expr)
102
101
}
103
102
}
104
103
105
104
/// Checks if `Mutex::lock` is called in any of the branches.
106
105
pub struct ArmVisitor < ' a , ' tcx > {
107
- found_mutex : Option < & ' tcx Expr < ' tcx > > ,
108
106
cx : & ' a LateContext < ' tcx > ,
109
107
}
110
108
111
109
impl < ' tcx > Visitor < ' tcx > for ArmVisitor < ' _ , ' tcx > {
112
- type Result = ControlFlow < ( ) > ;
113
- fn visit_expr ( & mut self , expr : & ' tcx Expr < ' tcx > ) -> ControlFlow < ( ) > {
110
+ type Result = ControlFlow < & ' tcx Expr < ' tcx > > ;
111
+ fn visit_expr ( & mut self , expr : & ' tcx Expr < ' tcx > ) -> ControlFlow < & ' tcx Expr < ' tcx > > {
114
112
if let Some ( mutex) = is_mutex_lock_call ( self . cx , expr) {
115
- self . found_mutex = Some ( mutex) ;
116
- return ControlFlow :: Break ( ( ) ) ;
113
+ return ControlFlow :: Break ( mutex) ;
117
114
}
118
- visit:: walk_expr ( self , expr) ;
119
- ControlFlow :: Continue ( ( ) )
115
+ visit:: walk_expr ( self , expr)
120
116
}
121
117
}
122
118
123
119
impl < ' tcx , ' l > ArmVisitor < ' tcx , ' l > {
124
- fn found_mutex_if_same_as ( & self , op_mutex : & Expr < ' _ > ) -> Option < & Expr < ' _ > > {
125
- self . found_mutex . and_then ( |arm_mutex| {
120
+ fn found_mutex_if_same_as ( & self , op_mutex : & Expr < ' _ > , found_mutex : Option < & ' tcx Expr < ' tcx > > ) -> Option < & Expr < ' _ > > {
121
+ found_mutex. and_then ( |arm_mutex| {
126
122
SpanlessEq :: new ( self . cx )
127
123
. eq_expr ( op_mutex, arm_mutex)
128
124
. then_some ( arm_mutex)
0 commit comments