diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-10-17 20:47:31 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-17 20:47:31 +0200 |
| commit | 372e8c11c27c3a6e017e8f08915b6ca02bcb62c8 (patch) | |
| tree | d9de2b8094d64bc7ce0628d65c1b6e5590b31be4 | |
| parent | 405eb4178e1eec5d8487b8790e5cfc7c9ad79c63 (diff) | |
| parent | 9b5b607fd813071ab85d67cae3d6517e3bd586e8 (diff) | |
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)
| -rw-r--r-- | library/std/src/os/unix/process.rs | 1 | ||||
| -rw-r--r-- | tests/ui/command/command-exec.rs | 8 |
2 files changed, 5 insertions, 4 deletions
diff --git a/library/std/src/os/unix/process.rs b/library/std/src/os/unix/process.rs index 9aadd949116..ef5adaf2290 100644 --- a/library/std/src/os/unix/process.rs +++ b/library/std/src/os/unix/process.rs @@ -154,6 +154,7 @@ pub trait CommandExt: Sealed { /// 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 diff --git a/tests/ui/command/command-exec.rs b/tests/ui/command/command-exec.rs index c97b8561410..d2545b0b472 100644 --- a/tests/ui/command/command-exec.rs +++ b/tests/ui/command/command-exec.rs @@ -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"); } |
