forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#125970 - RalfJung:before_exec, r=m-ou-se CommandExt::before_exec: deprecate safety in edition 2024 Similar to `set_var`, we had to find out after 1.0 was released that `before_exec` should have been unsafe. We partially rectified this by deprecating that function a long time ago, but since rust-lang#124636 we have the ability to also deprecate the safety of the old function and make it a *hard error* to call the old function outside `unsafe` in the next edition. So just in case anyone still uses the old function, let's ensure this can't be ignored when moving code to the new edition. Cc `@rust-lang/libs-api` Tracking: - rust-lang#124866
- Loading branch information
Showing
3 changed files
with
39 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0133]: call to unsafe function `before_exec` is unsafe and requires unsafe block | ||
--> $DIR/unsafe-before_exec.rs:14:5 | ||
| | ||
LL | cmd.before_exec(|| Ok(())); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function | ||
| | ||
= note: consult the function's documentation for information on how to avoid undefined behavior | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0133`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//@ revisions: e2021 e2024 | ||
//@ only-unix | ||
//@[e2021] edition: 2021 | ||
//@[e2021] check-pass | ||
//@[e2024] edition: 2024 | ||
//@[e2024] compile-flags: -Zunstable-options | ||
|
||
use std::process::Command; | ||
use std::os::unix::process::CommandExt; | ||
|
||
#[allow(deprecated)] | ||
fn main() { | ||
let mut cmd = Command::new("sleep"); | ||
cmd.before_exec(|| Ok(())); | ||
//[e2024]~^ ERROR call to unsafe function `before_exec` is unsafe | ||
drop(cmd); // we don't actually run the command. | ||
} |