Skip to content

Commit ae84e6e

Browse files
authored
Enable unsafe-attr-outside-unsafe 2024 edition lint (bytecodealliance#9964)
* Enable `unsafe-attr-outside-unsafe` 2024 edition lint This commit enables the `unsafe-attr-outside-unsafe` lint in rustc used in transitioning to the 2024 edition. This requires that the `#[no_mangle]` attribute is replaced in favor of `#[unsafe(no_mangle)]`. This mostly affects the C API of wasmtime and most of the changes here are a simple search/replace. * Another attribute update * Fix command adapter build
1 parent 0fff9c1 commit ae84e6e

File tree

41 files changed

+376
-370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+376
-370
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ unused-macro-rules = 'warn'
183183
# bit too noisy to enable wholesale but some selective items are ones we want to
184184
# opt-in to.
185185
keyword_idents_2024 = 'warn'
186+
unsafe-attr-outside-unsafe = 'warn'
186187
deprecated-safe-2024 = 'warn'
187188
rust-2024-guarded-string-incompatible-syntax = 'warn'
188189
rust-2024-prelude-collisions = 'warn'

crates/bench-api/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl WasmBenchConfig {
265265
/// that contains the engine's initialized state, and `0` is returned. On
266266
/// failure, a non-zero status code is returned and `out_bench_ptr` is left
267267
/// untouched.
268-
#[no_mangle]
268+
#[unsafe(no_mangle)]
269269
pub extern "C" fn wasm_bench_create(
270270
config: WasmBenchConfig,
271271
out_bench_ptr: *mut *mut c_void,
@@ -347,7 +347,7 @@ pub extern "C" fn wasm_bench_create(
347347
}
348348

349349
/// Free the engine state allocated by this library.
350-
#[no_mangle]
350+
#[unsafe(no_mangle)]
351351
pub extern "C" fn wasm_bench_free(state: *mut c_void) {
352352
assert!(!state.is_null());
353353
unsafe {
@@ -356,7 +356,7 @@ pub extern "C" fn wasm_bench_free(state: *mut c_void) {
356356
}
357357

358358
/// Compile the Wasm benchmark module.
359-
#[no_mangle]
359+
#[unsafe(no_mangle)]
360360
pub extern "C" fn wasm_bench_compile(
361361
state: *mut c_void,
362362
wasm_bytes: *const u8,
@@ -369,15 +369,15 @@ pub extern "C" fn wasm_bench_compile(
369369
}
370370

371371
/// Instantiate the Wasm benchmark module.
372-
#[no_mangle]
372+
#[unsafe(no_mangle)]
373373
pub extern "C" fn wasm_bench_instantiate(state: *mut c_void) -> ExitCode {
374374
let state = unsafe { (state as *mut BenchState).as_mut().unwrap() };
375375
let result = state.instantiate().context("failed to instantiate");
376376
to_exit_code(result)
377377
}
378378

379379
/// Execute the Wasm benchmark module.
380-
#[no_mangle]
380+
#[unsafe(no_mangle)]
381381
pub extern "C" fn wasm_bench_execute(state: *mut c_void) -> ExitCode {
382382
let state = unsafe { (state as *mut BenchState).as_mut().unwrap() };
383383
let result = state.execute().context("failed to execute");

crates/c-api-macros/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn declare_own(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
2626

2727
(quote! {
2828
#[doc = #docs]
29-
#[no_mangle]
29+
#[unsafe(no_mangle)]
3030
pub extern fn #delete(_: Box<#ty>) {}
3131
})
3232
.into()
@@ -48,7 +48,7 @@ pub fn declare_ty(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
4848
wasmtime_c_api_macros::declare_own!(#ty);
4949

5050
#[doc = #docs]
51-
#[no_mangle]
51+
#[unsafe(no_mangle)]
5252
pub extern fn #copy(src: &#ty) -> Box<#ty> {
5353
Box::new(src.clone())
5454
}
@@ -96,27 +96,27 @@ pub fn declare_ref(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
9696
wasmtime_c_api_macros::declare_ty!(#ty);
9797

9898
#[doc = #same_docs]
99-
#[no_mangle]
99+
#[unsafe(no_mangle)]
100100
pub extern fn #same(_a: &#ty, _b: &#ty) -> bool {
101101
eprintln!("`{}` is not implemented", stringify!(#same));
102102
std::process::abort();
103103
}
104104

105105
#[doc = #get_host_info_docs]
106-
#[no_mangle]
106+
#[unsafe(no_mangle)]
107107
pub extern fn #get_host_info(a: &#ty) -> *mut std::os::raw::c_void {
108108
std::ptr::null_mut()
109109
}
110110

111111
#[doc = #set_host_info_docs]
112-
#[no_mangle]
112+
#[unsafe(no_mangle)]
113113
pub extern fn #set_host_info(a: &#ty, info: *mut std::os::raw::c_void) {
114114
eprintln!("`{}` is not implemented", stringify!(#set_host_info));
115115
std::process::abort();
116116
}
117117

118118
#[doc = #set_host_info_final_docs]
119-
#[no_mangle]
119+
#[unsafe(no_mangle)]
120120
pub extern fn #set_host_info_final(
121121
a: &#ty,
122122
info: *mut std::os::raw::c_void,
@@ -127,14 +127,14 @@ pub fn declare_ref(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
127127
}
128128

129129
#[doc = #as_ref_docs]
130-
#[no_mangle]
130+
#[unsafe(no_mangle)]
131131
pub extern fn #as_ref(a: &#ty) -> Box<crate::wasm_ref_t> {
132132
eprintln!("`{}` is not implemented", stringify!(#as_ref));
133133
std::process::abort();
134134
}
135135

136136
#[doc = #as_ref_const_docs]
137-
#[no_mangle]
137+
#[unsafe(no_mangle)]
138138
pub extern fn #as_ref_const(a: &#ty) -> Box<crate::wasm_ref_t> {
139139
eprintln!("`{}` is not implemented", stringify!(#as_ref_const));
140140
std::process::abort();

crates/c-api/src/async.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@ use crate::{
1818
WASMTIME_I32,
1919
};
2020

21-
#[no_mangle]
21+
#[unsafe(no_mangle)]
2222
pub extern "C" fn wasmtime_config_async_support_set(c: &mut wasm_config_t, enable: bool) {
2323
c.config.async_support(enable);
2424
}
2525

26-
#[no_mangle]
26+
#[unsafe(no_mangle)]
2727
pub extern "C" fn wasmtime_config_async_stack_size_set(c: &mut wasm_config_t, size: usize) {
2828
c.config.async_stack_size(size);
2929
}
3030

31-
#[no_mangle]
31+
#[unsafe(no_mangle)]
3232
pub extern "C" fn wasmtime_context_epoch_deadline_async_yield_and_update(
3333
mut store: WasmtimeStoreContextMut<'_>,
3434
delta: u64,
3535
) {
3636
store.epoch_deadline_async_yield_and_update(delta);
3737
}
3838

39-
#[no_mangle]
39+
#[unsafe(no_mangle)]
4040
pub extern "C" fn wasmtime_context_fuel_async_yield_interval(
4141
mut store: WasmtimeStoreContextMut<'_>,
4242
interval: Option<NonZeroU64>,
@@ -194,10 +194,10 @@ pub struct wasmtime_call_future_t<'a> {
194194
underlying: Pin<Box<dyn Future<Output = ()> + 'a>>,
195195
}
196196

197-
#[no_mangle]
197+
#[unsafe(no_mangle)]
198198
pub extern "C" fn wasmtime_call_future_delete(_future: Box<wasmtime_call_future_t>) {}
199199

200-
#[no_mangle]
200+
#[unsafe(no_mangle)]
201201
pub extern "C" fn wasmtime_call_future_poll(future: &mut wasmtime_call_future_t) -> bool {
202202
let w = futures::task::noop_waker_ref();
203203
match future.underlying.as_mut().poll(&mut Context::from_waker(w)) {
@@ -242,7 +242,7 @@ async fn do_func_call_async(
242242
}
243243
}
244244

245-
#[no_mangle]
245+
#[unsafe(no_mangle)]
246246
pub unsafe extern "C" fn wasmtime_func_call_async<'a>(
247247
store: WasmtimeStoreContextMut<'a>,
248248
func: &'a Func,
@@ -270,7 +270,7 @@ pub unsafe extern "C" fn wasmtime_func_call_async<'a>(
270270
Box::new(wasmtime_call_future_t { underlying: fut })
271271
}
272272

273-
#[no_mangle]
273+
#[unsafe(no_mangle)]
274274
pub unsafe extern "C" fn wasmtime_linker_define_async_func(
275275
linker: &mut wasmtime_linker_t,
276276
module: *const u8,
@@ -308,7 +308,7 @@ async fn do_linker_instantiate_async(
308308
}
309309
}
310310

311-
#[no_mangle]
311+
#[unsafe(no_mangle)]
312312
pub extern "C" fn wasmtime_linker_instantiate_async<'a>(
313313
linker: &'a wasmtime_linker_t,
314314
store: WasmtimeStoreContextMut<'a>,
@@ -342,7 +342,7 @@ async fn do_instance_pre_instantiate_async(
342342
}
343343
}
344344

345-
#[no_mangle]
345+
#[unsafe(no_mangle)]
346346
pub extern "C" fn wasmtime_instance_pre_instantiate_async<'a>(
347347
instance_pre: &'a wasmtime_instance_pre_t,
348348
store: WasmtimeStoreContextMut<'a>,
@@ -438,7 +438,7 @@ unsafe impl StackCreator for CHostStackCreator {
438438
}
439439
}
440440

441-
#[no_mangle]
441+
#[unsafe(no_mangle)]
442442
pub unsafe extern "C" fn wasmtime_config_host_stack_creator_set(
443443
c: &mut wasm_config_t,
444444
creator: &wasmtime_stack_creator_t,

0 commit comments

Comments
 (0)