Skip to content

Commit 0fff9c1

Browse files
authored
Enable missing-unsafe-on-extern lint (#9963)
* Enable `missing-unsafe-on-extern` lint This'll be a hard error in the 2024 edition so go ahead and opt-in to it now to ease our future transition. * Fix adapter build * Fix custom c-api build * Fix fuzzer build * Fix some Windows `extern` blocks
1 parent 4f52f29 commit 0fff9c1

File tree

16 files changed

+28
-27
lines changed

16 files changed

+28
-27
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ jobs:
936936
with:
937937
submodules: true
938938
- uses: ./.github/actions/install-rust
939-
- run: cargo install cbindgen --vers "^0.26" --locked
939+
- run: cargo install cbindgen --vers "^0.27" --locked
940940
- run: rustup target add x86_64-unknown-none
941941
- run: ./build.sh x86_64-unknown-none
942942
working-directory: ./examples/min-platform

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ deprecated-safe-2024 = 'warn'
187187
rust-2024-guarded-string-incompatible-syntax = 'warn'
188188
rust-2024-prelude-collisions = 'warn'
189189
rust-2024-incompatible-pat = 'warn'
190+
missing-unsafe-on-extern = 'warn'
190191

191192
# Don't warn about unknown cfgs for pulley
192193
[workspace.lints.rust.unexpected_cfgs]

cranelift/filetests/src/function_runner.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ impl TestFileCompiler {
111111
// final binary doesn't link in `libm`.
112112
#[cfg(unix)]
113113
{
114-
extern "C" {
115-
fn ceilf(f: f32) -> f32;
114+
unsafe extern "C" {
115+
safe fn ceilf(f: f32) -> f32;
116116
}
117117
let f = 1.2_f32;
118-
assert_eq!(f.ceil(), unsafe { ceilf(f) });
118+
assert_eq!(f.ceil(), ceilf(f));
119119
}
120120

121121
let module = JITModule::new(builder);

crates/fiber/src/stackswitch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cfg_if::cfg_if! {
2323
}
2424
}
2525

26-
extern "C" {
26+
unsafe extern "C" {
2727
#[wasmtime_versioned_export_macros::versioned_link]
2828
pub(crate) fn wasmtime_fiber_init(
2929
top_of_stack: *mut u8,

crates/fiber/src/unix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ mod asan {
371371

372372
// These intrinsics are provided by the address sanitizer runtime. Their C
373373
// signatures were translated into Rust-isms here with `Option` and `&mut`.
374-
extern "C" {
374+
unsafe extern "C" {
375375
fn __sanitizer_start_switch_fiber(
376376
private_asan_pointer_save: Option<&mut *mut u8>,
377377
bottom: *const u8,

crates/fiber/src/windows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct StartState {
6464

6565
const FIBER_FLAG_FLOAT_SWITCH: u32 = 1;
6666

67-
extern "C" {
67+
unsafe extern "C" {
6868
#[wasmtime_versioned_export_macros::versioned_link]
6969
fn wasmtime_fiber_get_current() -> *mut c_void;
7070
}

crates/jit-debug/src/gdb_jit_int.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct JITDescriptor {
2727
first_entry: *mut JITCodeEntry,
2828
}
2929

30-
extern "C" {
30+
unsafe extern "C" {
3131
#[versioned_link]
3232
fn wasmtime_jit_debug_descriptor() -> *mut JITDescriptor;
3333
fn __jit_debug_register_code();

crates/test-programs/src/bin/preview2_adapter_badfd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn main() {
22
#[link(wasm_import_module = "wasi_snapshot_preview1")]
3-
extern "C" {
3+
unsafe extern "C" {
44
#[cfg_attr(target_arch = "wasm32", link_name = "adapter_open_badfd")]
55
fn adapter_open_badfd(fd: *mut u32) -> wasi::Errno;
66

crates/wasi-preview1-component-adapter/src/descriptors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ pub struct Descriptors {
150150

151151
#[cfg(not(feature = "proxy"))]
152152
#[link(wasm_import_module = "wasi:filesystem/[email protected]")]
153-
extern "C" {
153+
unsafe extern "C" {
154154
#[link_name = "get-directories"]
155155
fn wasi_filesystem_get_directories(rval: *mut PreopenList);
156156
}

crates/wasi-preview1-component-adapter/src/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ pub mod bindings {
114114
}
115115
}
116116

117-
#[export_name = "wasi:cli/[email protected]#run"]
117+
#[unsafe(export_name = "wasi:cli/[email protected]#run")]
118118
#[cfg(feature = "command")]
119-
pub unsafe extern "C" fn run() -> u32 {
119+
pub extern "C" fn run() -> u32 {
120120
#[link(wasm_import_module = "__main_module__")]
121-
extern "C" {
122-
fn _start();
121+
unsafe extern "C" {
122+
safe fn _start();
123123
}
124124
_start();
125125
0
@@ -457,7 +457,7 @@ impl BumpAlloc {
457457

458458
#[cfg(not(feature = "proxy"))]
459459
#[link(wasm_import_module = "wasi:cli/[email protected]")]
460-
extern "C" {
460+
unsafe extern "C" {
461461
#[link_name = "get-arguments"]
462462
fn wasi_cli_get_arguments(rval: *mut WasmStrList);
463463
#[link_name = "get-environment"]
@@ -2156,7 +2156,7 @@ pub unsafe extern "C" fn poll_oneoff(
21562156
}
21572157

21582158
#[link(wasm_import_module = "wasi:io/[email protected]")]
2159-
extern "C" {
2159+
unsafe extern "C" {
21602160
#[link_name = "poll"]
21612161
fn poll_import(pollables: *const Pollable, len: usize, rval: *mut ReadyList);
21622162
}
@@ -2731,7 +2731,7 @@ enum AllocationState {
27312731
}
27322732

27332733
#[expect(improper_ctypes, reason = "types behind pointers")]
2734-
extern "C" {
2734+
unsafe extern "C" {
27352735
fn get_state_ptr() -> *mut State;
27362736
fn set_state_ptr(state: *mut State);
27372737
fn get_allocation_state() -> AllocationState;
@@ -2764,7 +2764,7 @@ impl State {
27642764
#[cold]
27652765
fn new() -> *mut State {
27662766
#[link(wasm_import_module = "__main_module__")]
2767-
extern "C" {
2767+
unsafe extern "C" {
27682768
fn cabi_realloc(
27692769
old_ptr: *mut u8,
27702770
old_len: usize,

crates/wasmtime/src/runtime/vm/debug_builtins.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub unsafe extern "C" fn set_vmctx_memory(vmctx_ptr: *mut VMContext) {
3939
/// means they need to be referenced for the linker to include them which is
4040
/// what this function does with trickery in C.
4141
pub fn init() {
42-
extern "C" {
42+
unsafe extern "C" {
4343
#[wasmtime_versioned_export_macros::versioned_link]
4444
fn wasmtime_debug_builtins_init();
4545
}

crates/wasmtime/src/runtime/vm/sys/custom/capi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub type wasmtime_trap_handler_t =
5252
#[cfg(feature = "signals-based-traps")]
5353
pub enum wasmtime_memory_image {}
5454

55-
extern "C" {
55+
unsafe extern "C" {
5656
/// Creates a new virtual memory mapping of the `size` specified with
5757
/// protection bits specified in `prot_flags`.
5858
///

crates/wasmtime/src/runtime/vm/sys/unix/traphandlers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::vm::VMContext;
22

33
#[link(name = "wasmtime-helpers")]
4-
extern "C" {
4+
unsafe extern "C" {
55
#[wasmtime_versioned_export_macros::versioned_link]
66
#[allow(improper_ctypes)]
77
pub fn wasmtime_setjmp(

crates/wasmtime/src/runtime/vm/sys/unix/unwind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ cfg_if::cfg_if! {
2424
false
2525
}
2626
} else {
27-
extern "C" {
27+
unsafe extern "C" {
2828
// libunwind import
2929
fn __register_frame(fde: *const u8);
3030
fn __deregister_frame(fde: *const u8);

crates/wasmtime/src/runtime/vm/sys/windows/traphandlers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use windows_sys::Win32::System::Diagnostics::Debug::*;
88
use windows_sys::Win32::System::Kernel::*;
99

1010
#[link(name = "wasmtime-helpers")]
11-
extern "C" {
11+
unsafe extern "C" {
1212
#[wasmtime_versioned_export_macros::versioned_link]
1313
#[allow(improper_ctypes)]
1414
pub fn wasmtime_setjmp(

examples/min-platform/embedding/wasmtime-platform.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#ifndef _WASMTIME_PLATFORM_H
2424
#define _WASMTIME_PLATFORM_H
2525

26-
/* Generated with cbindgen:0.26.0 */
26+
/* Generated with cbindgen:0.27.0 */
2727

2828
#include <stdarg.h>
2929
#include <stdbool.h>
@@ -288,7 +288,7 @@ extern uint8_t *wasmtime_tls_get(void);
288288
extern void wasmtime_tls_set(uint8_t *ptr);
289289

290290
#ifdef __cplusplus
291-
} // extern "C"
292-
#endif // __cplusplus
291+
} // extern "C"
292+
#endif // __cplusplus
293293

294-
#endif /* _WASMTIME_PLATFORM_H */
294+
#endif /* _WASMTIME_PLATFORM_H */

0 commit comments

Comments
 (0)