Fix suggestion on CallToDeprecatedSafeFnRequiresUnsafe diagnostic
This commit is contained in:
parent
953aa57c75
commit
8aa0e905f4
4 changed files with 57 additions and 1 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
18
tests/ui/rust-2024/unsafe-before_exec-suggestion.fixed
Normal file
18
tests/ui/rust-2024/unsafe-before_exec-suggestion.fixed
Normal 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);
|
||||
}
|
||||
17
tests/ui/rust-2024/unsafe-before_exec-suggestion.rs
Normal file
17
tests/ui/rust-2024/unsafe-before_exec-suggestion.rs
Normal 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);
|
||||
}
|
||||
21
tests/ui/rust-2024/unsafe-before_exec-suggestion.stderr
Normal file
21
tests/ui/rust-2024/unsafe-before_exec-suggestion.stderr
Normal 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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue