Skip to content

Commit 71c7d44

Browse files
committed
Auto merge of #13462 - y21:issue13459, r=dswij
`zombie_processes`: consider `wait()` calls in nested bodies Fixes #13459 Small oversight. We weren't considering uses of the local in closures. changelog: none
2 parents db1bda3 + f06a46e commit 71c7d44

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Diff for: clippy_lints/src/zombie_processes.rs

+7
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> for WaitFinder<'_, 'tcx> {
123+
type NestedFilter = nested_filter::OnlyBodies;
122124
type Result = ControlFlow<BreakReason>;
123125

124126
fn visit_local(&mut self, l: &'tcx LetStmt<'tcx>) -> Self::Result {
@@ -204,6 +206,11 @@ impl<'tcx> Visitor<'tcx> for WaitFinder<'_, 'tcx> {
204206

205207
walk_expr(self, ex)
206208
}
209+
210+
fn nested_visit_map(&mut self) -> 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.

Diff for: tests/ui/zombie_processes.rs

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

136143
fn process_child(c: Child) {

0 commit comments

Comments
 (0)