Skip to content

Commit

Permalink
Auto merge of #13462 - y21:issue13459, r=dswij
Browse files Browse the repository at this point in the history
`zombie_processes`: consider `wait()` calls in nested bodies

Fixes #13459

Small oversight. We weren't considering uses of the local in closures.

changelog: none
  • Loading branch information
bors committed Oct 1, 2024
2 parents db1bda3 + f06a46e commit 71c7d44
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions clippy_lints/src/zombie_processes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/zombie_processes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 71c7d44

Please sign in to comment.