@@ -63,10 +63,11 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq {
63
63
if let hir:: PatKind :: Binding ( mode, canonical_id, ident, None ) = local. pat. kind;
64
64
if let hir:: StmtKind :: Expr ( ref if_) = expr. kind;
65
65
if let hir:: ExprKind :: If ( ref cond, ref then, ref else_) = if_. kind;
66
- if !LocalUsedVisitor :: new( canonical_id) . check_expr( cond) ;
66
+ let mut used_visitor = LocalUsedVisitor :: new( cx, canonical_id) ;
67
+ if !used_visitor. check_expr( cond) ;
67
68
if let hir:: ExprKind :: Block ( ref then, _) = then. kind;
68
- if let Some ( value) = check_assign( canonical_id, & * then) ;
69
- if !LocalUsedVisitor :: new ( canonical_id ) . check_expr( value) ;
69
+ if let Some ( value) = check_assign( cx , canonical_id, & * then) ;
70
+ if !used_visitor . check_expr( value) ;
70
71
then {
71
72
let span = stmt. span. to( if_. span) ;
72
73
@@ -78,7 +79,7 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq {
78
79
79
80
let ( default_multi_stmts, default ) = if let Some ( ref else_) = * else_ {
80
81
if let hir:: ExprKind :: Block ( ref else_, _) = else_. kind {
81
- if let Some ( default ) = check_assign( canonical_id, else_) {
82
+ if let Some ( default ) = check_assign( cx , canonical_id, else_) {
82
83
( else_. stmts. len( ) > 1 , default )
83
84
} else if let Some ( ref default ) = local. init {
84
85
( true , & * * default )
@@ -133,15 +134,19 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq {
133
134
}
134
135
}
135
136
136
- fn check_assign < ' tcx > ( decl : hir:: HirId , block : & ' tcx hir:: Block < ' _ > ) -> Option < & ' tcx hir:: Expr < ' tcx > > {
137
+ fn check_assign < ' tcx > (
138
+ cx : & LateContext < ' tcx > ,
139
+ decl : hir:: HirId ,
140
+ block : & ' tcx hir:: Block < ' _ > ,
141
+ ) -> Option < & ' tcx hir:: Expr < ' tcx > > {
137
142
if_chain ! {
138
143
if block. expr. is_none( ) ;
139
144
if let Some ( expr) = block. stmts. iter( ) . last( ) ;
140
145
if let hir:: StmtKind :: Semi ( ref expr) = expr. kind;
141
146
if let hir:: ExprKind :: Assign ( ref var, ref value, _) = expr. kind;
142
147
if path_to_local_id( var, decl) ;
143
148
then {
144
- let mut v = LocalUsedVisitor :: new( decl) ;
149
+ let mut v = LocalUsedVisitor :: new( cx , decl) ;
145
150
146
151
if block. stmts. iter( ) . take( block. stmts. len( ) -1 ) . any( |stmt| v. check_stmt( stmt) ) {
147
152
return None ;
0 commit comments