File tree Expand file tree Collapse file tree 3 files changed +39
-3
lines changed Expand file tree Collapse file tree 3 files changed +39
-3
lines changed Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff line change 1+ error[E0133]: call to unsafe function `before_exec` is unsafe and requires unsafe block
2+ --> $DIR/unsafe-before_exec.rs:14:5
3+ |
4+ LL | cmd.before_exec(|| Ok(()));
5+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
6+ |
7+ = note: consult the function's documentation for information on how to avoid undefined behavior
8+
9+ error: aborting due to 1 previous error
10+
11+ For more information about this error, try `rustc --explain E0133`.
Original file line number Diff line number Diff line change 1+ //@ revisions: e2021 e2024
2+ //@ only-unix
3+ //@[e2021] edition: 2021
4+ //@[e2021] check-pass
5+ //@[e2024] edition: 2024
6+ //@[e2024] compile-flags: -Zunstable-options
7+
8+ use std:: process:: Command ;
9+ use std:: os:: unix:: process:: CommandExt ;
10+
11+ #[ allow( deprecated) ]
12+ fn main ( ) {
13+ let mut cmd = Command :: new ( "sleep" ) ;
14+ cmd. before_exec ( || Ok ( ( ) ) ) ;
15+ //[e2024]~^ ERROR call to unsafe function `before_exec` is unsafe
16+ drop ( cmd) ; // we don't actually run the command.
17+ }
You can’t perform that action at this time.
0 commit comments