From de77683bcdabffd61010fc242c822700e5e6199b Mon Sep 17 00:00:00 2001 From: Ivan Tadeu Ferreira Antunes Filho Date: Thu, 24 Jul 2025 15:40:18 -0400 Subject: [PATCH] library/windows_targets: Fix macro expansion error in 'link' macro #144415 A recent change altered the definition of the link! macro when the windows_raw_dylib feature is enabled, changing its syntax from pub macro {..} to pub macro($tt:tt) {..} in #143592 This change introduced a build failure with the error: "macros that expand to items must be delimited with braces or followed by a semicolon". We revert this change, making it consistent with the link! macro when the windows_raw_dylib feature is not enabled. For the case when it is not enabled, it also makes use of code repetition in order to avoid the macro expansion error. If instead we try to reuse the code, as seen in #144415, we run into the same issue of "macros that expand to items must be delimited with braces or followed by a semicolon" --- library/windows_targets/src/lib.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/library/windows_targets/src/lib.rs b/library/windows_targets/src/lib.rs index 9e82e6a720006..7d04db6475588 100644 --- a/library/windows_targets/src/lib.rs +++ b/library/windows_targets/src/lib.rs @@ -33,8 +33,15 @@ pub macro link_dylib { } #[cfg(feature = "windows_raw_dylib")] -pub macro link($($tt:tt)*) { - $crate::link_raw_dylib!($($tt)*) +pub macro link{ + ($library:literal $abi:literal $($link_name:literal)? $(#[$doc:meta])? fn $($function:tt)*) => ( + #[cfg_attr(not(target_arch = "x86"), link(name = $library, kind = "raw-dylib", modifiers = "+verbatim"))] + #[cfg_attr(target_arch = "x86", link(name = $library, kind = "raw-dylib", modifiers = "+verbatim", import_name_type = "undecorated"))] + unsafe extern $abi { + $(#[link_name=$link_name])? + pub fn $($function)*; + } + ) } #[cfg(not(feature = "windows_raw_dylib"))]