Skip to content

Commit 34bab29

Browse files
authored
Rollup merge of #119948 - asquared31415:unsafe_op_in_unsafe_fn_fix, r=TaKO8Ki
Make `unsafe_op_in_unsafe_fn` migrated in edition 2024 fixes #119823
2 parents 8c3c8bb + a8bb418 commit 34bab29

14 files changed

+160
-51
lines changed

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,6 +2755,11 @@ declare_lint! {
27552755
pub UNSAFE_OP_IN_UNSAFE_FN,
27562756
Allow,
27572757
"unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
2758+
@future_incompatible = FutureIncompatibleInfo {
2759+
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
2760+
reference: "issue #71668 <https://github.com/rust-lang/rust/issues/71668>",
2761+
explain_reason: false
2762+
};
27582763
@edition Edition2024 => Warn;
27592764
}
27602765

compiler/rustc_mir_build/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ impl AddToDiagnostic for UnsafeNotInheritedLintNote {
430430
diag.tool_only_multipart_suggestion(
431431
fluent::mir_build_wrap_suggestion,
432432
vec![(body_start, "{ unsafe ".into()), (body_end, "}".into())],
433-
Applicability::MaybeIncorrect,
433+
Applicability::MachineApplicable,
434434
);
435435
}
436436
}

tests/ui/rfcs/rfc-2396-target_feature-11/safe-calls.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ error: call to function `sse2` with `#[target_feature]` is unsafe and requires u
9797
LL | sse2();
9898
| ^^^^^^ call to function with `#[target_feature]`
9999
|
100+
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
100101
= help: in order for the call to be safe, the context requires the following additional target feature: sse2
101102
= note: the sse2 target feature being enabled in the build configuration does not remove the requirement to list it in `#[target_feature]`
102103
note: an unsafe function restricts its caller, but its body is safe by default

tests/ui/unsafe/edition-2024-unsafe_op_in_unsafe_fn.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ warning: call to unsafe function `unsf` is unsafe and requires unsafe block (err
44
LL | unsf();
55
| ^^^^^^ call to unsafe function
66
|
7+
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
78
= note: consult the function's documentation for information on how to avoid undefined behavior
89
note: an unsafe function restricts its caller, but its body is safe by default
910
--> $DIR/edition-2024-unsafe_op_in_unsafe_fn.rs:9:1
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// edition: 2024
2+
// compile-flags: -Zunstable-options
3+
// check-pass
4+
5+
// Tests that `unsafe_op_in_unsafe_fn` is warn-by-default in edition 2024 and that the
6+
// `unused_unsafe` lint does not consider the inner unsafe block to be unused.
7+
#![crate_type = "lib"]
8+
#![deny(unused_unsafe)]
9+
10+
unsafe fn unsf() {}
11+
12+
unsafe fn foo() {
13+
unsf();
14+
//~^ WARN
15+
16+
// no unused_unsafe
17+
unsafe {
18+
unsf();
19+
}
20+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
warning: call to unsafe function `unsf` is unsafe and requires unsafe block (error E0133)
2+
--> $DIR/edition_2024_default.rs:13:5
3+
|
4+
LL | unsf();
5+
| ^^^^^^ call to unsafe function
6+
|
7+
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
8+
= note: consult the function's documentation for information on how to avoid undefined behavior
9+
note: an unsafe function restricts its caller, but its body is safe by default
10+
--> $DIR/edition_2024_default.rs:12:1
11+
|
12+
LL | unsafe fn foo() {
13+
| ^^^^^^^^^^^^^^^
14+
= note: `#[warn(unsafe_op_in_unsafe_fn)]` on by default
15+
16+
warning: 1 warning emitted
17+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![deny(rust_2024_compatibility)]
2+
#![crate_type = "lib"]
3+
4+
unsafe fn unsf() {}
5+
6+
unsafe fn foo() {
7+
unsf();
8+
//~^ ERROR call to unsafe function `unsf` is unsafe and requires unsafe block
9+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: call to unsafe function `unsf` is unsafe and requires unsafe block (error E0133)
2+
--> $DIR/in_2024_compatibility.rs:7:5
3+
|
4+
LL | unsf();
5+
| ^^^^^^ call to unsafe function
6+
|
7+
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
8+
= note: consult the function's documentation for information on how to avoid undefined behavior
9+
note: an unsafe function restricts its caller, but its body is safe by default
10+
--> $DIR/in_2024_compatibility.rs:6:1
11+
|
12+
LL | unsafe fn foo() {
13+
| ^^^^^^^^^^^^^^^
14+
note: the lint level is defined here
15+
--> $DIR/in_2024_compatibility.rs:1:9
16+
|
17+
LL | #![deny(rust_2024_compatibility)]
18+
| ^^^^^^^^^^^^^^^^^^^^^^^
19+
= note: `#[deny(unsafe_op_in_unsafe_fn)]` implied by `#[deny(rust_2024_compatibility)]`
20+
21+
error: aborting due to 1 previous error
22+

0 commit comments

Comments
 (0)