Fix suggestion on CallToDeprecatedSafeFnRequiresUnsafe diagnostic

This commit is contained in:
Jonathan Brouwer 2026-02-08 10:23:58 +01:00
parent 953aa57c75
commit 8aa0e905f4
No known key found for this signature in database
GPG key ID: 13619B051B673C52
4 changed files with 57 additions and 1 deletions

View file

@ -22,7 +22,7 @@ pub(crate) struct CallToDeprecatedSafeFnRequiresUnsafe {
#[derive(Subdiagnostic)]
#[multipart_suggestion(
"you can wrap the call in an `unsafe` block if you can guarantee that the environment access only happens in single-threaded code",
"you can wrap the call in an `unsafe` block if you can guarantee {$guarantee}",
applicability = "machine-applicable"
)]
pub(crate) struct CallToDeprecatedSafeFnRequiresUnsafeSub {

View file

@ -0,0 +1,18 @@
//@ edition:2015
//@ only-unix
//@ run-rustfix
#![deny(deprecated_safe_2024)]
use std::process::Command;
use std::os::unix::process::CommandExt;
#[allow(deprecated)]
fn main() {
let mut cmd = Command::new("sleep");
// TODO: Audit that the closure is async-signal-safe.
unsafe { cmd.before_exec(|| Ok(())) };
//~^ ERROR call to deprecated safe function
//~| WARN this is accepted in the current edition
drop(cmd);
}

View file

@ -0,0 +1,17 @@
//@ edition:2015
//@ only-unix
//@ run-rustfix
#![deny(deprecated_safe_2024)]
use std::process::Command;
use std::os::unix::process::CommandExt;
#[allow(deprecated)]
fn main() {
let mut cmd = Command::new("sleep");
cmd.before_exec(|| Ok(()));
//~^ ERROR call to deprecated safe function
//~| WARN this is accepted in the current edition
drop(cmd);
}

View file

@ -0,0 +1,21 @@
error: call to deprecated safe function `std::os::unix::process::CommandExt::before_exec` is unsafe and requires unsafe block
--> $DIR/unsafe-before_exec-suggestion.rs:13:5
|
LL | cmd.before_exec(|| Ok(()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/newly-unsafe-functions.html>
note: the lint level is defined here
--> $DIR/unsafe-before_exec-suggestion.rs:5:9
|
LL | #![deny(deprecated_safe_2024)]
| ^^^^^^^^^^^^^^^^^^^^
help: you can wrap the call in an `unsafe` block if you can guarantee that the closure is async-signal-safe
|
LL + // TODO: Audit that the closure is async-signal-safe.
LL ~ unsafe { cmd.before_exec(|| Ok(())) };
|
error: aborting due to 1 previous error