Skip to content

"spawned process is not wait()ed on in all code paths" when ? used in chain call before spawn() #14911

@lyskov

Description

@lyskov

Summary

Clippy flag command.spawn() code when ? used in daisy-chain calls before the spawn got called and .expect used on spawn invocation.

Interestingly, changing expect to ? on spawn() clear the the error:

fn test_1_passed() -> std::io::Result<String> {
    let (mut recv, send) = std::io::pipe()?;
    let mut command = Command::new("ls").stdout(send.try_clone()?).spawn()?;
    command.wait()?;
    Ok("".into())
}

Lint Name

clippy::zombie_processes

Reproducer

I tried this code:

fn test_1_flagged() -> std::io::Result<String> {
    let (mut recv, send) = std::io::pipe()?;
    let mut command = Command::new("ls")
    .stdout(send.try_clone()?)
    .spawn().expect("Could not spawn new process...");
    command.wait()?;
    Ok("".into())
}

I expected to see this happen: no issue

Instead, this happened: "spawned process is not wait()ed on in all code paths" highlighting send.try_clone()? as offending part.

Version

rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: aarch64-apple-darwin
release: 1.87.0
LLVM version: 20.1.1

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