Skip to content

Commit ba3a942

Browse files
authored
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
2 parents 0dbf8cf + 23d1309 commit ba3a942

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

std/src/os/unix/process.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,21 @@ pub trait CommandExt: Sealed {
109109
/// Schedules a closure to be run just before the `exec` function is
110110
/// invoked.
111111
///
112-
/// This method is stable and usable, but it should be unsafe. To fix
113-
/// that, it got deprecated in favor of the unsafe [`pre_exec`].
112+
/// `before_exec` used to be a safe method, but it needs to be unsafe since the closure may only
113+
/// perform operations that are *async-signal-safe*. Hence it got deprecated in favor of the
114+
/// unsafe [`pre_exec`]. Meanwhile, Rust gained the ability to make an existing safe method
115+
/// fully unsafe in a new edition, which is how `before_exec` became `unsafe`. It still also
116+
/// remains deprecated; `pre_exec` should be used instead.
114117
///
115118
/// [`pre_exec`]: CommandExt::pre_exec
116119
#[stable(feature = "process_exec", since = "1.15.0")]
117120
#[deprecated(since = "1.37.0", note = "should be unsafe, use `pre_exec` instead")]
118-
fn before_exec<F>(&mut self, f: F) -> &mut process::Command
121+
#[cfg_attr(bootstrap, rustc_deprecated_safe_2024)]
122+
#[cfg_attr(
123+
not(bootstrap),
124+
rustc_deprecated_safe_2024(audit_that = "the closure is async-signal-safe")
125+
)]
126+
unsafe fn before_exec<F>(&mut self, f: F) -> &mut process::Command
119127
where
120128
F: FnMut() -> io::Result<()> + Send + Sync + 'static,
121129
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy