Rollup merge of #131833 - c-ryan747:patch-1, r=Noratrieb

Add `must_use` to `CommandExt::exec`

[CommandExt::exec](https://fburl.com/0qhpo7nu) returns a `std::io::Error` in the case exec fails, but its not currently marked as `must_use` making it easy to accidentally ignore it.

This PR adds the `must_use` attributed here as i think it fits the definition in the guide of [When to add #[must_use]](https://std-dev-guide.rust-lang.org/policy/must-use.html#when-to-add-must_use)
This commit is contained in:
Matthias Krüger 2024-10-17 20:47:31 +02:00 committed by GitHub
commit 372e8c11c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 4 deletions

View File

@ -154,6 +154,7 @@ unsafe fn before_exec<F>(&mut self, f: F) -> &mut process::Command
/// required to gracefully handle errors it is recommended to use the
/// cross-platform `spawn` instead.
#[stable(feature = "process_exec2", since = "1.9.0")]
#[must_use]
fn exec(&mut self) -> io::Error;
/// Set executable argument

View File

@ -26,23 +26,23 @@ fn main() {
}
"exec-test2" => {
Command::new("/path/to/nowhere").exec();
let _ = Command::new("/path/to/nowhere").exec();
println!("passed");
}
"exec-test3" => {
Command::new(&me).arg("bad\0").exec();
let _ = Command::new(&me).arg("bad\0").exec();
println!("passed");
}
"exec-test4" => {
Command::new(&me).current_dir("/path/to/nowhere").exec();
let _ = Command::new(&me).current_dir("/path/to/nowhere").exec();
println!("passed");
}
"exec-test5" => {
env::set_var("VARIABLE", "ABC");
Command::new("definitely-not-a-real-binary").env("VARIABLE", "XYZ").exec();
let _ = Command::new("definitely-not-a-real-binary").env("VARIABLE", "XYZ").exec();
assert_eq!(env::var("VARIABLE").unwrap(), "ABC");
println!("passed");
}