Skip to content
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

Consider adding #[must_use] to std::process::ExitStatus #73127

Open
ijackson opened this issue Jun 8, 2020 · 0 comments
Open

Consider adding #[must_use] to std::process::ExitStatus #73127

ijackson opened this issue Jun 8, 2020 · 0 comments
Labels
A-process Area: `std::process` and `std::env` C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@ijackson
Copy link
Contributor

ijackson commented Jun 8, 2020

Hi. Normally, Rust makes it difficult to accidentally write code which ignores errors. This is one of its great strengths. However, the std::process API requires the user to explicitly check the process exit status.

(This issue is about the return value from wait(). I am filing another one about output(). See also #70186 which is about the return value from spawn().)

Here's a demo of the problem.

use std::process::*;

fn main() {
    let command = ["ls","--no-such-option"];
    Command::new(command[0])
                     .args(&command[1..])
                     .spawn().expect("Failed spawn")
                     .wait().expect("Failed wait");
    println!("I ran {:?}", &command);
    
    println!("All went well!")
}

(Playground)

It produces this output:

   Compiling playground v0.0.1 (/playground)
    Finished dev [unoptimized + debuginfo] target(s) in 0.98s
     Running `target/debug/playground`
ls: unrecognized option '--no-such-option'
Try 'ls --help' for more information.

Standard Output

I ran ["ls", "--no-such-option"]
All went well!

This is not optimal. I think making ExitStatus be #[must_use] would be the best way to address this. The code above would then generate a compiler error. The programmer would be prompted to make an actual decision about the exit status.

@jonas-schievink jonas-schievink added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jun 8, 2020
ijackson added a commit to ijackson/rust that referenced this issue Jan 28, 2021
For the same reason as `Result` is #[must_use]

Cloess: rust-lang#73127
Signed-off-by: Ian Jackson <[email protected]>
ijackson added a commit to ijackson/rust that referenced this issue May 12, 2021
Closes rust-lang#73125

This is in pursuance of
  Issue rust-lang#73127 Consider adding #[must_use] to std::process::ExitStatus

In
  MR rust-lang#81452 Add #[must_use] to [...] process::ExitStatus
we concluded that the existing arrangements in are too awkward
so adding that #[must_use] is blocked on improving the ergonomics.

I wrote a mini-RFC-style discusion of the approach in
  rust-lang#73125 (comment)

Signed-off-by: Ian Jackson <[email protected]>
@workingjubilee workingjubilee added the A-process Area: `std::process` and `std::env` label Jul 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-process Area: `std::process` and `std::env` C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants