Skip to content

Commit 62ad5d4

Browse files
committed
Expand macro gating
1 parent a787d03 commit 62ad5d4

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/macros.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,21 @@ cfg_if! {
164164
}
165165
)*)
166166
}
167+
168+
macro_rules! const_fn {
169+
($($({$constness:ident})* fn $i:ident(
170+
$($arg:ident: $argty:ty),*
171+
) -> $ret:ty {
172+
$($body:stmt);*
173+
})*) => ($(
174+
#[inline]
175+
$($constness)* fn $i($($arg: $argty),*
176+
) -> $ret {
177+
$($body);*
178+
}
179+
)*)
180+
}
181+
167182
} else {
168183
#[allow(unused_macros)]
169184
macro_rules! f {
@@ -173,7 +188,22 @@ cfg_if! {
173188
$($body:stmt);*
174189
})*) => ($(
175190
#[inline]
176-
pub unsafe extern fn $i($($arg: $argty),*) -> $ret {
191+
pub unsafe extern fn $i($($arg: $argty),*
192+
) -> $ret {
193+
$($body);*
194+
}
195+
)*)
196+
}
197+
198+
macro_rules! const_fn {
199+
($($({$constness:ident})* fn $i:ident(
200+
$($arg:ident: $argty:ty),*
201+
) -> $ret:ty {
202+
$($body:stmt);*
203+
})*) => ($(
204+
#[inline]
205+
fn $i($($arg: $argty),*
206+
) -> $ret {
177207
$($body);*
178208
}
179209
)*)

src/unix/linux_like/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,8 +1165,10 @@ pub const ARPHRD_IEEE802154: u16 = 804;
11651165
pub const ARPHRD_VOID: u16 = 0xFFFF;
11661166
pub const ARPHRD_NONE: u16 = 0xFFFE;
11671167

1168-
const fn CMSG_ALIGN(len: usize) -> usize {
1169-
len + ::mem::size_of::<usize>() - 1 & !(::mem::size_of::<usize>() - 1)
1168+
const_fn! {
1169+
{const} fn CMSG_ALIGN(len: usize) -> usize {
1170+
len + ::mem::size_of::<usize>() - 1 & !(::mem::size_of::<usize>() - 1)
1171+
}
11701172
}
11711173

11721174
f! {

0 commit comments

Comments
 (0)