mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-05 11:33:04 +00:00
make unsafe_op_in_unsafe_fn MachineApplicable and add it to 2024 compatibility
This commit is contained in:
parent
bfcc027a75
commit
a8bb418ae5
@ -2755,6 +2755,11 @@ declare_lint! {
|
||||
pub UNSAFE_OP_IN_UNSAFE_FN,
|
||||
Allow,
|
||||
"unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
|
||||
reference: "issue #71668 <https://github.com/rust-lang/rust/issues/71668>",
|
||||
explain_reason: false
|
||||
};
|
||||
@edition Edition2024 => Warn;
|
||||
}
|
||||
|
||||
|
@ -430,7 +430,7 @@ impl AddToDiagnostic for UnsafeNotInheritedLintNote {
|
||||
diag.tool_only_multipart_suggestion(
|
||||
fluent::mir_build_wrap_suggestion,
|
||||
vec![(body_start, "{ unsafe ".into()), (body_end, "}".into())],
|
||||
Applicability::MaybeIncorrect,
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -97,6 +97,7 @@ error: call to function `sse2` with `#[target_feature]` is unsafe and requires u
|
||||
LL | sse2();
|
||||
| ^^^^^^ call to function with `#[target_feature]`
|
||||
|
|
||||
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
|
||||
= help: in order for the call to be safe, the context requires the following additional target feature: sse2
|
||||
= note: the sse2 target feature being enabled in the build configuration does not remove the requirement to list it in `#[target_feature]`
|
||||
note: an unsafe function restricts its caller, but its body is safe by default
|
||||
|
@ -4,6 +4,7 @@ warning: call to unsafe function `unsf` is unsafe and requires unsafe block (err
|
||||
LL | unsf();
|
||||
| ^^^^^^ call to unsafe function
|
||||
|
|
||||
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
|
||||
= note: consult the function's documentation for information on how to avoid undefined behavior
|
||||
note: an unsafe function restricts its caller, but its body is safe by default
|
||||
--> $DIR/edition-2024-unsafe_op_in_unsafe_fn.rs:9:1
|
||||
|
@ -0,0 +1,20 @@
|
||||
// edition: 2024
|
||||
// compile-flags: -Zunstable-options
|
||||
// check-pass
|
||||
|
||||
// Tests that `unsafe_op_in_unsafe_fn` is warn-by-default in edition 2024 and that the
|
||||
// `unused_unsafe` lint does not consider the inner unsafe block to be unused.
|
||||
#![crate_type = "lib"]
|
||||
#![deny(unused_unsafe)]
|
||||
|
||||
unsafe fn unsf() {}
|
||||
|
||||
unsafe fn foo() {
|
||||
unsf();
|
||||
//~^ WARN
|
||||
|
||||
// no unused_unsafe
|
||||
unsafe {
|
||||
unsf();
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
warning: call to unsafe function `unsf` is unsafe and requires unsafe block (error E0133)
|
||||
--> $DIR/edition_2024_default.rs:13:5
|
||||
|
|
||||
LL | unsf();
|
||||
| ^^^^^^ call to unsafe function
|
||||
|
|
||||
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
|
||||
= note: consult the function's documentation for information on how to avoid undefined behavior
|
||||
note: an unsafe function restricts its caller, but its body is safe by default
|
||||
--> $DIR/edition_2024_default.rs:12:1
|
||||
|
|
||||
LL | unsafe fn foo() {
|
||||
| ^^^^^^^^^^^^^^^
|
||||
= note: `#[warn(unsafe_op_in_unsafe_fn)]` on by default
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
@ -0,0 +1,9 @@
|
||||
#![deny(rust_2024_compatibility)]
|
||||
#![crate_type = "lib"]
|
||||
|
||||
unsafe fn unsf() {}
|
||||
|
||||
unsafe fn foo() {
|
||||
unsf();
|
||||
//~^ ERROR call to unsafe function `unsf` is unsafe and requires unsafe block
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
error: call to unsafe function `unsf` is unsafe and requires unsafe block (error E0133)
|
||||
--> $DIR/in_2024_compatibility.rs:7:5
|
||||
|
|
||||
LL | unsf();
|
||||
| ^^^^^^ call to unsafe function
|
||||
|
|
||||
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
|
||||
= note: consult the function's documentation for information on how to avoid undefined behavior
|
||||
note: an unsafe function restricts its caller, but its body is safe by default
|
||||
--> $DIR/in_2024_compatibility.rs:6:1
|
||||
|
|
||||
LL | unsafe fn foo() {
|
||||
| ^^^^^^^^^^^^^^^
|
||||
note: the lint level is defined here
|
||||
--> $DIR/in_2024_compatibility.rs:1:9
|
||||
|
|
||||
LL | #![deny(rust_2024_compatibility)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: `#[deny(unsafe_op_in_unsafe_fn)]` implied by `#[deny(rust_2024_compatibility)]`
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
@ -4,6 +4,7 @@ error: call to unsafe function `unsf` is unsafe and requires unsafe block (error
|
||||
LL | unsf();
|
||||
| ^^^^^^ call to unsafe function
|
||||
|
|
||||
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
|
||||
= note: consult the function's documentation for information on how to avoid undefined behavior
|
||||
note: an unsafe function restricts its caller, but its body is safe by default
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:8:1
|
||||
@ -22,6 +23,7 @@ error: dereference of raw pointer is unsafe and requires unsafe block (error E01
|
||||
LL | *PTR;
|
||||
| ^^^^ dereference of raw pointer
|
||||
|
|
||||
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
|
||||
= note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
|
||||
|
||||
error: use of mutable static is unsafe and requires unsafe block (error E0133)
|
||||
@ -30,6 +32,7 @@ error: use of mutable static is unsafe and requires unsafe block (error E0133)
|
||||
LL | VOID = ();
|
||||
| ^^^^ use of mutable static
|
||||
|
|
||||
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
|
||||
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
|
||||
|
||||
error: unnecessary `unsafe` block
|
||||
@ -50,6 +53,7 @@ error: call to unsafe function `unsf` is unsafe and requires unsafe block (error
|
||||
LL | unsf();
|
||||
| ^^^^^^ call to unsafe function
|
||||
|
|
||||
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
|
||||
= note: consult the function's documentation for information on how to avoid undefined behavior
|
||||
note: an unsafe function restricts its caller, but its body is safe by default
|
||||
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:23:1
|
||||
@ -69,6 +73,7 @@ error: dereference of raw pointer is unsafe and requires unsafe block (error E01
|
||||
LL | *PTR;
|
||||
| ^^^^ dereference of raw pointer
|
||||
|
|
||||
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
|
||||
= note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
|
||||
|
||||
error: use of mutable static is unsafe and requires unsafe block (error E0133)
|
||||
@ -77,6 +82,7 @@ error: use of mutable static is unsafe and requires unsafe block (error E0133)
|
||||
LL | VOID = ();
|
||||
| ^^^^ use of mutable static
|
||||
|
|
||||
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
|
||||
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
|
||||
|
||||
error: unnecessary `unsafe` block
|
@ -11,50 +11,60 @@ unsafe fn unsf() {}
|
||||
pub unsafe fn foo() { unsafe {
|
||||
//~^ NOTE an unsafe function restricts its caller, but its body is safe by default
|
||||
unsf(); //~ ERROR call to unsafe function `unsf` is unsafe
|
||||
//~^ NOTE
|
||||
//~| NOTE
|
||||
//~^ NOTE call to unsafe function
|
||||
//~| NOTE for more information, see issue #71668
|
||||
//~| NOTE consult the function's documentation
|
||||
unsf(); //~ ERROR call to unsafe function `unsf` is unsafe
|
||||
//~^ NOTE
|
||||
//~| NOTE
|
||||
//~^ NOTE call to unsafe function
|
||||
//~| NOTE for more information, see issue #71668
|
||||
//~| NOTE consult the function's documentation
|
||||
}}
|
||||
|
||||
pub unsafe fn bar(x: *const i32) -> i32 { unsafe {
|
||||
//~^ NOTE an unsafe function restricts its caller, but its body is safe by default
|
||||
let y = *x; //~ ERROR dereference of raw pointer is unsafe and requires unsafe block
|
||||
//~^ NOTE
|
||||
//~| NOTE
|
||||
//~^ NOTE dereference of raw pointer
|
||||
//~| NOTE for more information, see issue #71668
|
||||
//~| NOTE raw pointers may be null
|
||||
y + *x //~ ERROR dereference of raw pointer is unsafe and requires unsafe block
|
||||
//~^ NOTE
|
||||
//~| NOTE
|
||||
//~^ NOTE dereference of raw pointer
|
||||
//~| NOTE for more information, see issue #71668
|
||||
//~| NOTE raw pointers may be null
|
||||
}}
|
||||
|
||||
static mut BAZ: i32 = 0;
|
||||
pub unsafe fn baz() -> i32 { unsafe {
|
||||
//~^ NOTE an unsafe function restricts its caller, but its body is safe by default
|
||||
let y = BAZ; //~ ERROR use of mutable static is unsafe and requires unsafe block
|
||||
//~^ NOTE
|
||||
//~| NOTE
|
||||
//~^ NOTE use of mutable static
|
||||
//~| NOTE for more information, see issue #71668
|
||||
//~| NOTE mutable statics can be mutated by multiple threads
|
||||
y + BAZ //~ ERROR use of mutable static is unsafe and requires unsafe block
|
||||
//~^ NOTE
|
||||
//~| NOTE
|
||||
//~^ NOTE use of mutable static
|
||||
//~| NOTE for more information, see issue #71668
|
||||
//~| NOTE mutable statics can be mutated by multiple threads
|
||||
}}
|
||||
|
||||
macro_rules! unsafe_macro { () => (unsf()) }
|
||||
//~^ ERROR call to unsafe function `unsf` is unsafe
|
||||
//~| NOTE
|
||||
//~| NOTE
|
||||
//~| NOTE call to unsafe function
|
||||
//~| NOTE for more information, see issue #71668
|
||||
//~| NOTE consult the function's documentation
|
||||
//~| ERROR call to unsafe function `unsf` is unsafe
|
||||
//~| NOTE
|
||||
//~| NOTE
|
||||
//~| NOTE call to unsafe function
|
||||
//~| NOTE for more information, see issue #71668
|
||||
//~| NOTE consult the function's documentation
|
||||
|
||||
pub unsafe fn unsafe_in_macro() { unsafe {
|
||||
//~^ NOTE an unsafe function restricts its caller, but its body is safe by default
|
||||
unsafe_macro!();
|
||||
//~^ NOTE
|
||||
//~| NOTE
|
||||
//~^ NOTE in this expansion
|
||||
//~| NOTE in this expansion
|
||||
//~| NOTE in this expansion
|
||||
unsafe_macro!();
|
||||
//~^ NOTE
|
||||
//~| NOTE
|
||||
//~^ NOTE in this expansion
|
||||
//~| NOTE in this expansion
|
||||
//~| NOTE in this expansion
|
||||
}}
|
||||
|
||||
pub unsafe fn unsafe_in_external_macro() {
|
@ -11,50 +11,60 @@ unsafe fn unsf() {}
|
||||
pub unsafe fn foo() {
|
||||
//~^ NOTE an unsafe function restricts its caller, but its body is safe by default
|
||||
unsf(); //~ ERROR call to unsafe function `unsf` is unsafe
|
||||
//~^ NOTE
|
||||
//~| NOTE
|
||||
//~^ NOTE call to unsafe function
|
||||
//~| NOTE for more information, see issue #71668
|
||||
//~| NOTE consult the function's documentation
|
||||
unsf(); //~ ERROR call to unsafe function `unsf` is unsafe
|
||||
//~^ NOTE
|
||||
//~| NOTE
|
||||
//~^ NOTE call to unsafe function
|
||||
//~| NOTE for more information, see issue #71668
|
||||
//~| NOTE consult the function's documentation
|
||||
}
|
||||
|
||||
pub unsafe fn bar(x: *const i32) -> i32 {
|
||||
//~^ NOTE an unsafe function restricts its caller, but its body is safe by default
|
||||
let y = *x; //~ ERROR dereference of raw pointer is unsafe and requires unsafe block
|
||||
//~^ NOTE
|
||||
//~| NOTE
|
||||
//~^ NOTE dereference of raw pointer
|
||||
//~| NOTE for more information, see issue #71668
|
||||
//~| NOTE raw pointers may be null
|
||||
y + *x //~ ERROR dereference of raw pointer is unsafe and requires unsafe block
|
||||
//~^ NOTE
|
||||
//~| NOTE
|
||||
//~^ NOTE dereference of raw pointer
|
||||
//~| NOTE for more information, see issue #71668
|
||||
//~| NOTE raw pointers may be null
|
||||
}
|
||||
|
||||
static mut BAZ: i32 = 0;
|
||||
pub unsafe fn baz() -> i32 {
|
||||
//~^ NOTE an unsafe function restricts its caller, but its body is safe by default
|
||||
let y = BAZ; //~ ERROR use of mutable static is unsafe and requires unsafe block
|
||||
//~^ NOTE
|
||||
//~| NOTE
|
||||
//~^ NOTE use of mutable static
|
||||
//~| NOTE for more information, see issue #71668
|
||||
//~| NOTE mutable statics can be mutated by multiple threads
|
||||
y + BAZ //~ ERROR use of mutable static is unsafe and requires unsafe block
|
||||
//~^ NOTE
|
||||
//~| NOTE
|
||||
//~^ NOTE use of mutable static
|
||||
//~| NOTE for more information, see issue #71668
|
||||
//~| NOTE mutable statics can be mutated by multiple threads
|
||||
}
|
||||
|
||||
macro_rules! unsafe_macro { () => (unsf()) }
|
||||
//~^ ERROR call to unsafe function `unsf` is unsafe
|
||||
//~| NOTE
|
||||
//~| NOTE
|
||||
//~| NOTE call to unsafe function
|
||||
//~| NOTE for more information, see issue #71668
|
||||
//~| NOTE consult the function's documentation
|
||||
//~| ERROR call to unsafe function `unsf` is unsafe
|
||||
//~| NOTE
|
||||
//~| NOTE
|
||||
//~| NOTE call to unsafe function
|
||||
//~| NOTE for more information, see issue #71668
|
||||
//~| NOTE consult the function's documentation
|
||||
|
||||
pub unsafe fn unsafe_in_macro() {
|
||||
//~^ NOTE an unsafe function restricts its caller, but its body is safe by default
|
||||
unsafe_macro!();
|
||||
//~^ NOTE
|
||||
//~| NOTE
|
||||
//~^ NOTE in this expansion
|
||||
//~| NOTE in this expansion
|
||||
//~| NOTE in this expansion
|
||||
unsafe_macro!();
|
||||
//~^ NOTE
|
||||
//~| NOTE
|
||||
//~^ NOTE in this expansion
|
||||
//~| NOTE in this expansion
|
||||
//~| NOTE in this expansion
|
||||
}
|
||||
|
||||
pub unsafe fn unsafe_in_external_macro() {
|
@ -4,6 +4,7 @@ error: call to unsafe function `unsf` is unsafe and requires unsafe block (error
|
||||
LL | unsf();
|
||||
| ^^^^^^ call to unsafe function
|
||||
|
|
||||
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
|
||||
= note: consult the function's documentation for information on how to avoid undefined behavior
|
||||
note: an unsafe function restricts its caller, but its body is safe by default
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:11:1
|
||||
@ -17,57 +18,62 @@ LL | #![deny(unsafe_op_in_unsafe_fn)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: call to unsafe function `unsf` is unsafe and requires unsafe block (error E0133)
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:16:5
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:17:5
|
||||
|
|
||||
LL | unsf();
|
||||
| ^^^^^^ call to unsafe function
|
||||
|
|
||||
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
|
||||
= note: consult the function's documentation for information on how to avoid undefined behavior
|
||||
|
||||
error: dereference of raw pointer is unsafe and requires unsafe block (error E0133)
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:23:13
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:25:13
|
||||
|
|
||||
LL | let y = *x;
|
||||
| ^^ dereference of raw pointer
|
||||
|
|
||||
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
|
||||
= note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
|
||||
note: an unsafe function restricts its caller, but its body is safe by default
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:21:1
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:23:1
|
||||
|
|
||||
LL | pub unsafe fn bar(x: *const i32) -> i32 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: dereference of raw pointer is unsafe and requires unsafe block (error E0133)
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:26:9
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:29:9
|
||||
|
|
||||
LL | y + *x
|
||||
| ^^ dereference of raw pointer
|
||||
|
|
||||
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
|
||||
= note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
|
||||
|
||||
error: use of mutable static is unsafe and requires unsafe block (error E0133)
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:34:13
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:38:13
|
||||
|
|
||||
LL | let y = BAZ;
|
||||
| ^^^ use of mutable static
|
||||
|
|
||||
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
|
||||
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
|
||||
note: an unsafe function restricts its caller, but its body is safe by default
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:32:1
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:36:1
|
||||
|
|
||||
LL | pub unsafe fn baz() -> i32 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: use of mutable static is unsafe and requires unsafe block (error E0133)
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:37:9
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:42:9
|
||||
|
|
||||
LL | y + BAZ
|
||||
| ^^^ use of mutable static
|
||||
|
|
||||
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
|
||||
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
|
||||
|
||||
error: call to unsafe function `unsf` is unsafe and requires unsafe block (error E0133)
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:42:36
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:48:36
|
||||
|
|
||||
LL | macro_rules! unsafe_macro { () => (unsf()) }
|
||||
| ^^^^^^ call to unsafe function
|
||||
@ -75,16 +81,17 @@ LL | macro_rules! unsafe_macro { () => (unsf()) }
|
||||
LL | unsafe_macro!();
|
||||
| --------------- in this macro invocation
|
||||
|
|
||||
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
|
||||
= note: consult the function's documentation for information on how to avoid undefined behavior
|
||||
note: an unsafe function restricts its caller, but its body is safe by default
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:50:1
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:58:1
|
||||
|
|
||||
LL | pub unsafe fn unsafe_in_macro() {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: this error originates in the macro `unsafe_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: call to unsafe function `unsf` is unsafe and requires unsafe block (error E0133)
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:42:36
|
||||
--> $DIR/wrapping-unsafe-block-sugg.rs:48:36
|
||||
|
|
||||
LL | macro_rules! unsafe_macro { () => (unsf()) }
|
||||
| ^^^^^^ call to unsafe function
|
||||
@ -92,6 +99,7 @@ LL | macro_rules! unsafe_macro { () => (unsf()) }
|
||||
LL | unsafe_macro!();
|
||||
| --------------- in this macro invocation
|
||||
|
|
||||
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
|
||||
= note: consult the function's documentation for information on how to avoid undefined behavior
|
||||
= note: this error originates in the macro `unsafe_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
Loading…
Reference in New Issue
Block a user