diff options
| author | y21 <30553356+y21@users.noreply.github.com> | 2024-09-26 14:08:22 +0200 |
|---|---|---|
| committer | y21 <30553356+y21@users.noreply.github.com> | 2024-10-01 19:21:30 +0200 |
| commit | f06a46ee4dc7587c5f353dc2e396e996068cebac (patch) | |
| tree | 6d1b6c9a23e6c43b7ceabef1a392139d5a846640 | |
| parent | db1bda3df17729f73235fb5dbc1726bf2efae6e7 (diff) | |
| download | rust-f06a46ee4dc7587c5f353dc2e396e996068cebac.tar.gz rust-f06a46ee4dc7587c5f353dc2e396e996068cebac.zip | |
consider `wait()` calls in nested bodies
| -rw-r--r-- | clippy_lints/src/zombie_processes.rs | 7 | ||||
| -rw-r--r-- | tests/ui/zombie_processes.rs | 7 |
2 files changed, 14 insertions, 0 deletions
diff --git a/clippy_lints/src/zombie_processes.rs b/clippy_lints/src/zombie_processes.rs index 58d71bee299..8d9241cc7d9 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<BreakReason>; 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 a2abc7fc3a1..b41bcce3f7f 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) { |
