Skip to content

Commit 372e8c1

Browse files
authored
Rollup merge of rust-lang#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)
2 parents 405eb41 + 9b5b607 commit 372e8c1

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

library/std/src/os/unix/process.rs

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ pub trait CommandExt: Sealed {
154154
/// required to gracefully handle errors it is recommended to use the
155155
/// cross-platform `spawn` instead.
156156
#[stable(feature = "process_exec2", since = "1.9.0")]
157+
#[must_use]
157158
fn exec(&mut self) -> io::Error;
158159

159160
/// Set executable argument

tests/ui/command/command-exec.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ fn main() {
2626
}
2727

2828
"exec-test2" => {
29-
Command::new("/path/to/nowhere").exec();
29+
let _ = Command::new("/path/to/nowhere").exec();
3030
println!("passed");
3131
}
3232

3333
"exec-test3" => {
34-
Command::new(&me).arg("bad\0").exec();
34+
let _ = Command::new(&me).arg("bad\0").exec();
3535
println!("passed");
3636
}
3737

3838
"exec-test4" => {
39-
Command::new(&me).current_dir("/path/to/nowhere").exec();
39+
let _ = Command::new(&me).current_dir("/path/to/nowhere").exec();
4040
println!("passed");
4141
}
4242

4343
"exec-test5" => {
4444
env::set_var("VARIABLE", "ABC");
45-
Command::new("definitely-not-a-real-binary").env("VARIABLE", "XYZ").exec();
45+
let _ = Command::new("definitely-not-a-real-binary").env("VARIABLE", "XYZ").exec();
4646
assert_eq!(env::var("VARIABLE").unwrap(), "ABC");
4747
println!("passed");
4848
}

0 commit comments

Comments
 (0)