Skip to content

Commit 5e560e7

Browse files
committed
Gate emitting 'const extern fn' behind a feature
1 parent 6e1e77e commit 5e560e7

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ std = []
2828
align = []
2929
rustc-dep-of-std = ['align', 'rustc-std-workspace-core']
3030
extra_traits = []
31+
const-fn = []
3132
# use_std is deprecated, use `std` instead
3233
use_std = [ 'std' ]
3334

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#![no_std]
3535
#![cfg_attr(feature = "rustc-dep-of-std", no_core)]
3636
#![cfg_attr(target_os = "redox", feature(static_nobundle))]
37-
#![feature(const_extern_fn)]
37+
#![cfg_attr(feature = "const-fn", feature(const_extern_fn))]
3838

3939
#[macro_use]
4040
mod macros;

src/macros.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,31 @@ macro_rules! s_no_extra_traits {
121121
);
122122
}
123123

124-
#[allow(unused_macros)]
125-
macro_rules! f {
126-
($(pub fn $i:ident($($arg:ident: $argty:ty),*) $($constness:ident)* -> $ret:ty {
127-
$($body:stmt);*
128-
})*) => ($(
129-
#[inline]
130-
pub $($constness)* unsafe extern fn $i($($arg: $argty),*) -> $ret {
131-
$($body);*
124+
cfg_if! {
125+
if #[cfg(feature = "const-fn")] {
126+
#[allow(unused_macros)]
127+
macro_rules! f {
128+
($(pub fn $i:ident($($arg:ident: $argty:ty),*) $($constness:ident)* -> $ret:ty {
129+
$($body:stmt);*
130+
})*) => ($(
131+
#[inline]
132+
pub $($constness)* unsafe extern fn $i($($arg: $argty),*) -> $ret {
133+
$($body);*
134+
}
135+
)*)
132136
}
133-
)*)
137+
} else {
138+
macro_rules! f {
139+
($(pub fn $i:ident($($arg:ident: $argty:ty),*) $($constness:ident)* -> $ret:ty {
140+
$($body:stmt);*
141+
})*) => ($(
142+
#[inline]
143+
pub unsafe extern fn $i($($arg: $argty),*) -> $ret {
144+
$($body);*
145+
}
146+
)*)
147+
}
148+
}
134149
}
135150

136151
#[allow(unused_macros)]

0 commit comments

Comments
 (0)