Skip to content

zombie_processes: false positive with returns inside closures #14677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jgallagher opened this issue Apr 23, 2025 · 1 comment · Fixed by #14696
Closed

zombie_processes: false positive with returns inside closures #14677

jgallagher opened this issue Apr 23, 2025 · 1 comment · Fixed by #14696
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@jgallagher
Copy link

jgallagher commented Apr 23, 2025

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

@jgallagher jgallagher added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Apr 23, 2025
@profetia
Copy link
Contributor

@rustbot claim

github-merge-queue bot pushed a commit that referenced this issue Apr 28, 2025
Closes #14677

changelog: [`zombie_processes`] fix FP inside closures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants