@@ -63,10 +63,11 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq {
6363 if let hir:: PatKind :: Binding ( mode, canonical_id, ident, None ) = local. pat. kind;
6464 if let hir:: StmtKind :: Expr ( ref if_) = expr. kind;
6565 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) ;
6768 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) ;
7071 then {
7172 let span = stmt. span. to( if_. span) ;
7273
@@ -78,7 +79,7 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq {
7879
7980 let ( default_multi_stmts, default ) = if let Some ( ref else_) = * else_ {
8081 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_) {
8283 ( else_. stmts. len( ) > 1 , default )
8384 } else if let Some ( ref default ) = local. init {
8485 ( true , & * * default )
@@ -133,15 +134,19 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq {
133134 }
134135}
135136
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 > > {
137142 if_chain ! {
138143 if block. expr. is_none( ) ;
139144 if let Some ( expr) = block. stmts. iter( ) . last( ) ;
140145 if let hir:: StmtKind :: Semi ( ref expr) = expr. kind;
141146 if let hir:: ExprKind :: Assign ( ref var, ref value, _) = expr. kind;
142147 if path_to_local_id( var, decl) ;
143148 then {
144- let mut v = LocalUsedVisitor :: new( decl) ;
149+ let mut v = LocalUsedVisitor :: new( cx , decl) ;
145150
146151 if block. stmts. iter( ) . take( block. stmts. len( ) -1 ) . any( |stmt| v. check_stmt( stmt) ) {
147152 return None ;
0 commit comments