Skip to content

Commit

Permalink
Rollup merge of rust-lang#125970 - RalfJung:before_exec, r=m-ou-se
Browse files Browse the repository at this point in the history
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
matthiaskrgr authored Aug 14, 2024
2 parents 0dbf8cf + 23d1309 commit ba3a942
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions std/src/os/unix/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,21 @@ pub trait CommandExt: Sealed {
/// Schedules a closure to be run just before the `exec` function is
/// invoked.
///
/// This method is stable and usable, but it should be unsafe. To fix
/// that, it got deprecated in favor of the unsafe [`pre_exec`].
/// `before_exec` used to be a safe method, but it needs to be unsafe since the closure may only
/// perform operations that are *async-signal-safe*. Hence it got deprecated in favor of the
/// unsafe [`pre_exec`]. Meanwhile, Rust gained the ability to make an existing safe method
/// fully unsafe in a new edition, which is how `before_exec` became `unsafe`. It still also
/// remains deprecated; `pre_exec` should be used instead.
///
/// [`pre_exec`]: CommandExt::pre_exec
#[stable(feature = "process_exec", since = "1.15.0")]
#[deprecated(since = "1.37.0", note = "should be unsafe, use `pre_exec` instead")]
fn before_exec<F>(&mut self, f: F) -> &mut process::Command
#[cfg_attr(bootstrap, rustc_deprecated_safe_2024)]
#[cfg_attr(
not(bootstrap),
rustc_deprecated_safe_2024(audit_that = "the closure is async-signal-safe")
)]
unsafe fn before_exec<F>(&mut self, f: F) -> &mut process::Command
where
F: FnMut() -> io::Result<()> + Send + Sync + 'static,
{
Expand Down

0 comments on commit ba3a942

Please sign in to comment.