From f06a46ee4dc7587c5f353dc2e396e996068cebac Mon Sep 17 00:00:00 2001 From: y21 <30553356+y21@users.noreply.github.com> Date: Thu, 26 Sep 2024 14:08:22 +0200 Subject: [PATCH] consider `wait()` calls in nested bodies --- clippy_lints/src/zombie_processes.rs | 7 +++++++ tests/ui/zombie_processes.rs | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/clippy_lints/src/zombie_processes.rs b/clippy_lints/src/zombie_processes.rs index 58d71bee2..8d9241cc7 100644 --- a/clippy_lints/src/zombie_processes.rs +++ b/clippy_lints/src/zombie_processes.rs @@ -6,6 +6,7 @@ use rustc_errors::Applicability; use rustc_hir::intravisit::{Visitor, walk_block, walk_expr, walk_local}; use rustc_hir::{Expr, ExprKind, HirId, LetStmt, Node, PatKind, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::hir::nested_filter; use rustc_session::declare_lint_pass; use rustc_span::sym; use std::ops::ControlFlow; @@ -119,6 +120,7 @@ enum WaitFinder<'a, 'tcx> { } impl<'tcx> Visitor<'tcx> for WaitFinder<'_, 'tcx> { + type NestedFilter = nested_filter::OnlyBodies; type Result = ControlFlow; fn visit_local(&mut self, l: &'tcx LetStmt<'tcx>) -> Self::Result { @@ -204,6 +206,11 @@ impl<'tcx> Visitor<'tcx> for WaitFinder<'_, 'tcx> { walk_expr(self, ex) } + + fn nested_visit_map(&mut self) -> Self::Map { + let (Self::Found(cx, _) | Self::WalkUpTo(cx, _)) = self; + cx.tcx.hir() + } } /// This function has shared logic between the different kinds of nodes that can trigger the lint. diff --git a/tests/ui/zombie_processes.rs b/tests/ui/zombie_processes.rs index a2abc7fc3..b41bcce3f 100644 --- a/tests/ui/zombie_processes.rs +++ b/tests/ui/zombie_processes.rs @@ -131,6 +131,13 @@ fn main() { } x.wait().unwrap(); } + + { + let mut x = Command::new("").spawn().unwrap(); + std::thread::spawn(move || { + x.wait().unwrap(); + }); + } } fn process_child(c: Child) {