Skip to content

Commit b80abda

Browse files
committed
Deny unsafe_op_in_unsafe_fn by default
Edition 2024 requires that we avoid this. There is a lot of code that will need to be adjusted, so start the process here.
1 parent 45007cc commit b80abda

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

builtins-test-intrinsics/src/main.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -647,14 +647,14 @@ fn something_with_a_dtor(f: &dyn Fn()) {
647647
f();
648648
}
649649

650-
#[no_mangle]
650+
#[unsafe(no_mangle)]
651651
#[cfg(not(thumb))]
652652
fn main(_argc: core::ffi::c_int, _argv: *const *const u8) -> core::ffi::c_int {
653653
run();
654654
0
655655
}
656656

657-
#[no_mangle]
657+
#[unsafe(no_mangle)]
658658
#[cfg(thumb)]
659659
pub fn _start() -> ! {
660660
run();
@@ -667,30 +667,30 @@ pub fn _start() -> ! {
667667
extern "C" {}
668668

669669
// ARM targets need these symbols
670-
#[no_mangle]
670+
#[unsafe(no_mangle)]
671671
pub fn __aeabi_unwind_cpp_pr0() {}
672672

673-
#[no_mangle]
673+
#[unsafe(no_mangle)]
674674
pub fn __aeabi_unwind_cpp_pr1() {}
675675

676676
#[cfg(not(any(windows, target_os = "cygwin")))]
677677
#[allow(non_snake_case)]
678-
#[no_mangle]
678+
#[unsafe(no_mangle)]
679679
pub fn _Unwind_Resume() {}
680680

681681
#[cfg(not(any(windows, target_os = "cygwin")))]
682682
#[lang = "eh_personality"]
683-
#[no_mangle]
683+
#[unsafe(no_mangle)]
684684
pub extern "C" fn eh_personality() {}
685685

686686
#[cfg(any(all(windows, target_env = "gnu"), target_os = "cygwin"))]
687687
mod mingw_unwinding {
688-
#[no_mangle]
688+
#[unsafe(no_mangle)]
689689
pub fn rust_eh_personality() {}
690-
#[no_mangle]
690+
#[unsafe(no_mangle)]
691691
pub fn rust_eh_unwind_resume() {}
692-
#[no_mangle]
692+
#[unsafe(no_mangle)]
693693
pub fn rust_eh_register_frames() {}
694-
#[no_mangle]
694+
#[unsafe(no_mangle)]
695695
pub fn rust_eh_unregister_frames() {}
696696
}

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#![allow(clippy::manual_swap)]
2323
// Support compiling on both stage0 and stage1 which may differ in supported stable features.
2424
#![allow(stable_features)]
25+
// By default, disallow this as it is forbidden in edition 2024. There is a lot of unsafe code to
26+
// be migrated, however, so exceptions exist.
27+
#![deny(unsafe_op_in_unsafe_fn)]
2528

2629
// We disable #[no_mangle] for tests so that we can verify the test results
2730
// against the native compiler-rt implementations of the builtins.

src/macros.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ macro_rules! intrinsics {
256256

257257
#[cfg(all(target_vendor = "apple", any(target_arch = "x86", target_arch = "x86_64"), not(feature = "mangled-names")))]
258258
mod $name {
259-
#[no_mangle]
259+
#[unsafe(no_mangle)]
260260
#[cfg_attr(not(any(all(windows, target_env = "gnu"), target_os = "cygwin")), linkage = "weak")]
261261
$(#[$($attr)*])*
262262
extern $abi fn $name( $($argname: u16),* ) $(-> $ret)? {
@@ -292,7 +292,7 @@ macro_rules! intrinsics {
292292

293293
#[cfg(all(target_vendor = "apple", any(target_arch = "x86", target_arch = "x86_64"), not(feature = "mangled-names")))]
294294
mod $name {
295-
#[no_mangle]
295+
#[unsafe(no_mangle)]
296296
#[cfg_attr(not(any(all(windows, target_env = "gnu"), target_os = "cygwin")), linkage = "weak")]
297297
$(#[$($attr)*])*
298298
extern $abi fn $name( $($argname: $ty),* ) -> u16 {
@@ -333,7 +333,7 @@ macro_rules! intrinsics {
333333

334334
#[cfg(all(target_arch = "arm", not(feature = "mangled-names")))]
335335
mod $name {
336-
#[no_mangle]
336+
#[unsafe(no_mangle)]
337337
#[cfg_attr(not(any(all(windows, target_env = "gnu"), target_os = "cygwin")), linkage = "weak")]
338338
$(#[$($attr)*])*
339339
extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
@@ -343,7 +343,7 @@ macro_rules! intrinsics {
343343

344344
#[cfg(all(target_arch = "arm", not(feature = "mangled-names")))]
345345
mod $alias {
346-
#[no_mangle]
346+
#[unsafe(no_mangle)]
347347
#[cfg_attr(not(any(all(windows, target_env = "gnu"), target_os = "cygwin")), linkage = "weak")]
348348
$(#[$($attr)*])*
349349
extern "aapcs" fn $alias( $($argname: $ty),* ) $(-> $ret)? {
@@ -410,7 +410,7 @@ macro_rules! intrinsics {
410410
#[cfg(all(feature = "mem", not(feature = "mangled-names")))]
411411
mod $name {
412412
$(#[$($attr)*])*
413-
#[no_mangle]
413+
#[unsafe(no_mangle)]
414414
#[cfg_attr(not(any(all(windows, target_env = "gnu"), target_os = "cygwin")), linkage = "weak")]
415415
unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
416416
super::$name($($argname),*)
@@ -502,7 +502,7 @@ macro_rules! intrinsics {
502502
#[cfg(not(feature = "mangled-names"))]
503503
mod $name {
504504
$(#[$($attr)*])*
505-
#[no_mangle]
505+
#[unsafe(no_mangle)]
506506
#[cfg_attr(not(any(all(windows, target_env = "gnu"), target_os = "cygwin")), linkage = "weak")]
507507
$(unsafe $($empty)?)? extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
508508
super::$name($($argname),*)

src/mem/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Trying to satisfy clippy here is hopeless
22
#![allow(clippy::style)]
3+
#![allow(unsafe_op_in_unsafe_fn)]
34

45
#[allow(warnings)]
56
#[cfg(target_pointer_width = "16")]

src/x86_64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ intrinsics! {
4444
// HACK(https://github.com/rust-lang/rust/issues/62785): x86_64-unknown-uefi needs special LLVM
4545
// support unless we emit the _fltused
4646
mod _fltused {
47-
#[no_mangle]
47+
#[unsafe(no_mangle)]
4848
#[used]
4949
#[cfg(target_os = "uefi")]
5050
static _fltused: i32 = 0;

0 commit comments

Comments
 (0)