Skip to content

Commit 0fff9c1

Browse files
authored
Enable missing-unsafe-on-extern lint (bytecodealliance#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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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/preopens@0.2.2")]
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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ pub mod bindings {
114114
}
115115
}
116116

117-
#[export_name = "wasi:cli/run@0.2.3#run"]
117+
#[unsafe(export_name = "wasi:cli/run@0.2.3#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/environment@0.2.3")]
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/poll@0.2.3")]
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,

0 commit comments

Comments
 (0)