Skip to content

Commit f06a46e

Browse files
committed
consider wait() calls in nested bodies
1 parent db1bda3 commit f06a46e

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

‎clippy_lints/src/zombie_processes.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_errors::Applicability;
66
use rustc_hir::intravisit::{Visitor, walk_block, walk_expr, walk_local};
77
use rustc_hir::{Expr,ExprKind,HirId,LetStmt,Node,PatKind,Stmt,StmtKind};
88
use rustc_lint::{LateContext,LateLintPass};
9+
use rustc_middle::hir::nested_filter;
910
use rustc_session::declare_lint_pass;
1011
use rustc_span::sym;
1112
use std::ops::ControlFlow;
@@ -119,6 +120,7 @@ enum WaitFinder<'a, 'tcx> {
119120
}
120121

121122
impl<'tcx>Visitor<'tcx>forWaitFinder<'_,'tcx>{
123+
typeNestedFilter = nested_filter::OnlyBodies;
122124
typeResult = ControlFlow<BreakReason>;
123125

124126
fnvisit_local(&mutself,l:&'tcxLetStmt<'tcx>) -> Self::Result{
@@ -204,6 +206,11 @@ impl<'tcx> Visitor<'tcx> for WaitFinder<'_, 'tcx> {
204206

205207
walk_expr(self, ex)
206208
}
209+
210+
fnnested_visit_map(&mutself) -> Self::Map{
211+
let(Self::Found(cx, _) | Self::WalkUpTo(cx, _)) = self;
212+
cx.tcx.hir()
213+
}
207214
}
208215

209216
/// This function has shared logic between the different kinds of nodes that can trigger the lint.

‎tests/ui/zombie_processes.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ fn main() {
131131
}
132132
x.wait().unwrap();
133133
}
134+
135+
{
136+
letmut x = Command::new("").spawn().unwrap();
137+
std::thread::spawn(move || {
138+
x.wait().unwrap();
139+
});
140+
}
134141
}
135142

136143
fnprocess_child(c:Child){

0 commit comments

Comments
 (0)