From 83e37f933478de23a903a4725e4336df62636ab5 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 16 Aug 2022 16:44:16 -0500 Subject: [PATCH] Fix a compile error on nightly Rust (#4724) It looks like Rust nightly has gotten a bit more strict about attributes-on-expressions and previously accepted code is no longer accepted. This commit updates the generated code for a macro to a form which is accepted by rustc. --- crates/wasmtime/src/component/func.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/crates/wasmtime/src/component/func.rs b/crates/wasmtime/src/component/func.rs index 396d6d83c1..fceab79a96 100644 --- a/crates/wasmtime/src/component/func.rs +++ b/crates/wasmtime/src/component/func.rs @@ -37,15 +37,20 @@ use wasmtime_runtime::{Export, ExportFunction, VMTrampoline}; #[doc(hidden)] #[macro_export] macro_rules! map_maybe_uninit { - ($maybe_uninit:ident $($field:tt)*) => (#[allow(unused_unsafe)] unsafe { - use $crate::component::__internal::MaybeUninitExt; + ($maybe_uninit:ident $($field:tt)*) => ({ + #[allow(unused_unsafe)] + { + unsafe { + use $crate::component::__internal::MaybeUninitExt; - let m: &mut std::mem::MaybeUninit<_> = $maybe_uninit; - // Note the usage of `addr_of_mut!` here which is an attempt to "stay - // safe" here where we never accidentally create `&mut T` where `T` is - // actually uninitialized, hopefully appeasing the Rust unsafe - // guidelines gods. - m.map(|p| std::ptr::addr_of_mut!((*p)$($field)*)) + let m: &mut std::mem::MaybeUninit<_> = $maybe_uninit; + // Note the usage of `addr_of_mut!` here which is an attempt to "stay + // safe" here where we never accidentally create `&mut T` where `T` is + // actually uninitialized, hopefully appeasing the Rust unsafe + // guidelines gods. + m.map(|p| std::ptr::addr_of_mut!((*p)$($field)*)) + } + } }) }