Skip to content

Commit de77683

Browse files
authored
library/windows_targets: Fix macro expansion error in 'link' macro rust-lang#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 rust-lang#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 rust-lang#144415, we run into the same issue of "macros that expand to items must be delimited with braces or followed by a semicolon"
1 parent 5d22242 commit de77683

File tree

1 file changed

+9
-2
lines changed
  • library/windows_targets/src

1 file changed

+9
-2
lines changed

library/windows_targets/src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,15 @@ pub macro link_dylib {
3333
}
3434

3535
#[cfg(feature = "windows_raw_dylib")]
36-
pub macro link($($tt:tt)*) {
37-
$crate::link_raw_dylib!($($tt)*)
36+
pub macro link{
37+
($library:literal $abi:literal $($link_name:literal)? $(#[$doc:meta])? fn $($function:tt)*) => (
38+
#[cfg_attr(not(target_arch = "x86"), link(name = $library, kind = "raw-dylib", modifiers = "+verbatim"))]
39+
#[cfg_attr(target_arch = "x86", link(name = $library, kind = "raw-dylib", modifiers = "+verbatim", import_name_type = "undecorated"))]
40+
unsafe extern $abi {
41+
$(#[link_name=$link_name])?
42+
pub fn $($function)*;
43+
}
44+
)
3845
}
3946

4047
#[cfg(not(feature = "windows_raw_dylib"))]

0 commit comments

Comments
 (0)