Skip to content

zombie_processes: false positive with returns inside closures #14677

Closed
@jgallagher

Description

@jgallagher

Summary

The zombie_processes lint emits a warning for early returns inside closures that don't affect the lifetime of the child process itself.

Lint Name

zombie_processes

Reproducer

I tried this code:

fn foo<F>(f: F)
where F: Fn() -> Result<(), ()> {
    _ = f();
}

fn main() {
    let mut child = std::process::Command::new("true").spawn().unwrap();
    let some_condition = true;
    foo(|| {
        if some_condition {
            return Err(());
        }
        Ok(())
    });
    child.kill().unwrap();
    child.wait().unwrap();
}

playground

I saw this happen:

    Checking playground v0.0.1 (/playground)
warning: spawned process is not `wait()`ed on in all code paths
  --> src/main.rs:7:21
   |
7  |     let mut child = std::process::Command::new("true").spawn().unwrap();
   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: no `wait()` call exists on the code path to this early return
  --> src/main.rs:11:13
   |
11 |             return Err(());
   |             ^^^^^^^^^^^^^^
note: `wait()` call exists, but it is unreachable due to the early return
  --> src/main.rs:16:5
   |
16 |     child.wait().unwrap();
   |     ^^^^^
   = help: consider calling `.wait()` in all code paths
   = note: not doing so might leave behind zombie processes
   = note: see https://doc.rust-lang.org/stable/std/process/struct.Child.html#warning
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#zombie_processes
   = note: `#[warn(clippy::zombie_processes)]` on by default

warning: `playground` (bin "playground") generated 1 warning

I expected to see this happen:

No warnings; the "early return" referenced by the lint is not an early return from the function where child exists.

Version

rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.86.0
LLVM version: 19.1.7

Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions