Skip to content

Commit fa7e411

Browse files
committed
Drop the libc_const_extern_fn conditional
Additionally deprecate the `const-extern-fn` feature. This is possible since the MSRV was increased to 1.63.
1 parent a8ed1c2 commit fa7e411

File tree

9 files changed

+54
-148
lines changed

9 files changed

+54
-148
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Raw FFI bindings to platform libraries like libc.
1818
"""
1919

2020
[package.metadata.docs.rs]
21-
features = ["const-extern-fn", "extra_traits"]
21+
features = ["extra_traits"]
2222
default-target = "x86_64-unknown-linux-gnu"
2323
targets = [
2424
"aarch64-apple-darwin",
@@ -141,6 +141,8 @@ default = ["std"]
141141
std = []
142142
rustc-dep-of-std = ['align', 'rustc-std-workspace-core']
143143
extra_traits = []
144+
145+
# `const-extern-function` is deprecated and no longer does anything
144146
const-extern-fn = []
145147

146148
# `align` is deprecated and no longer does anything

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ libc = "0.2"
4949
* `extra_traits`: all `struct`s implemented in `libc` are `Copy` and `Clone`.
5050
This feature derives `Debug`, `Eq`, `Hash`, and `PartialEq`.
5151

52-
* `const-extern-fn`: Changes some `extern fn`s into `const extern fn`s. If you
53-
use Rust >= 1.62, this feature is implicitly enabled. Otherwise it requires a
54-
nightly rustc.
52+
The following features are deprecated:
53+
54+
* `use_std`: this is equivalent to `std`
55+
* `const-extern-fn`: this is now enabled by default
56+
* `align`: this is now enabled by default
5557

5658
## Rust version support
5759

build.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
1414
"freebsd13",
1515
"freebsd14",
1616
"freebsd15",
17-
"libc_const_extern_fn",
18-
"libc_const_extern_fn_unstable",
1917
"libc_deny_warnings",
2018
"libc_long_array",
2119
"libc_thread_local",
@@ -42,9 +40,8 @@ fn main() {
4240
// Avoid unnecessary re-building.
4341
println!("cargo:rerun-if-changed=build.rs");
4442

45-
let (rustc_minor_ver, is_nightly) = rustc_minor_nightly();
43+
let (rustc_minor_ver, _is_nightly) = rustc_minor_nightly();
4644
let rustc_dep_of_std = env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();
47-
let const_extern_fn_cargo_feature = env::var("CARGO_FEATURE_CONST_EXTERN_FN").is_ok();
4845
let libc_ci = env::var("LIBC_CI").is_ok();
4946
let libc_check_cfg = env::var("LIBC_CHECK_CFG").is_ok() || rustc_minor_ver >= 80;
5047

@@ -96,20 +93,6 @@ fn main() {
9693
set_cfg("libc_thread_local");
9794
}
9895

99-
// Rust >= 1.62.0 allows to use `const_extern_fn` for "Rust" and "C".
100-
if rustc_minor_ver >= 62 {
101-
set_cfg("libc_const_extern_fn");
102-
} else {
103-
// Rust < 1.62.0 requires a crate feature and feature gate.
104-
if const_extern_fn_cargo_feature {
105-
if !is_nightly || rustc_minor_ver < 40 {
106-
panic!("const-extern-fn requires a nightly compiler >= 1.40");
107-
}
108-
set_cfg("libc_const_extern_fn_unstable");
109-
set_cfg("libc_const_extern_fn");
110-
}
111-
}
112-
11396
// check-cfg is a nightly cargo/rustc feature to warn when unknown cfgs are used across the
11497
// codebase. libc can configure it if the appropriate environment variable is passed. Since
11598
// rust-lang/rust enforces it, this is useful when using a custom libc fork there.

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#![deny(missing_copy_implementations, safe_packed_borrows)]
2727
#![cfg_attr(not(feature = "rustc-dep-of-std"), no_std)]
2828
#![cfg_attr(feature = "rustc-dep-of-std", no_core)]
29-
#![cfg_attr(libc_const_extern_fn_unstable, feature(const_extern_fn))]
3029

3130
#[macro_use]
3231
mod macros;

src/macros.rs

Lines changed: 38 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -214,104 +214,52 @@ macro_rules! e {
214214
// 1. Avoid ambiguity errors from 'macro_rules!' (which happen when writing '$foo:ident fn'
215215
// 2. Allow users of this macro to mix 'pub fn foo' and 'pub const fn bar' within the same
216216
// 'f!' block
217-
cfg_if! {
218-
if #[cfg(libc_const_extern_fn)] {
219-
/// Define an `unsafe` function that is const as long as `const-extern-fn` is enabled.
220-
macro_rules! f {
221-
($(
222-
$(#[$attr:meta])*
223-
pub $({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),*) -> $ret:ty {
224-
$($body:stmt);*
225-
}
226-
)*) => ($(
227-
#[inline]
228-
$(#[$attr])*
229-
pub $($constness)* unsafe extern fn $i($($arg: $argty),*) -> $ret {
230-
$($body);*
231-
}
232-
)*)
217+
/// Define an `unsafe` function that is const as long as `const-extern-fn` is enabled.
218+
macro_rules! f {
219+
($(
220+
$(#[$attr:meta])*
221+
pub $({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),*) -> $ret:ty {
222+
$($body:stmt);*
233223
}
234-
235-
/// Define a safe function that is const as long as `const-extern-fn` is enabled.
236-
macro_rules! safe_f {
237-
($(
238-
$(#[$attr:meta])*
239-
pub $({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),*) -> $ret:ty {
240-
$($body:stmt);*
241-
}
242-
)*) => ($(
243-
#[inline]
244-
$(#[$attr])*
245-
pub $($constness)* extern fn $i($($arg: $argty),*) -> $ret {
246-
$($body);*
247-
}
248-
)*)
224+
)*) => ($(
225+
#[inline]
226+
$(#[$attr])*
227+
pub $($constness)* unsafe extern fn $i($($arg: $argty),*) -> $ret {
228+
$($body);*
249229
}
230+
)*)
231+
}
250232

251-
/// A nonpublic function that is const as long as `const-extern-fn` is enabled.
252-
macro_rules! const_fn {
253-
($(
254-
$(#[$attr:meta])*
255-
$({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),*) -> $ret:ty {
256-
$($body:stmt);*
257-
}
258-
)*) => ($(
259-
#[inline]
260-
$(#[$attr])*
261-
$($constness)* fn $i($($arg: $argty),*) -> $ret {
262-
$($body);*
263-
}
264-
)*)
233+
/// Define a safe function that is const as long as `const-extern-fn` is enabled.
234+
macro_rules! safe_f {
235+
($(
236+
$(#[$attr:meta])*
237+
pub $({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),*) -> $ret:ty {
238+
$($body:stmt);*
265239
}
266-
} else {
267-
/// Define an `unsafe` function that is const as long as `const-extern-fn` is enabled.
268-
macro_rules! f {
269-
($(
270-
$(#[$attr:meta])*
271-
pub $({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),*) -> $ret:ty {
272-
$($body:stmt);*
273-
}
274-
)*) => ($(
275-
#[inline]
276-
$(#[$attr])*
277-
pub unsafe extern fn $i($($arg: $argty),*) -> $ret {
278-
$($body);*
279-
}
280-
)*)
240+
)*) => ($(
241+
#[inline]
242+
$(#[$attr])*
243+
pub $($constness)* extern fn $i($($arg: $argty),*) -> $ret {
244+
$($body);*
281245
}
246+
)*)
247+
}
282248

283-
/// Define a safe function that is const as long as `const-extern-fn` is enabled.
284-
macro_rules! safe_f {
285-
($(
286-
$(#[$attr:meta])*
287-
pub $({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),*) -> $ret:ty {
288-
$($body:stmt);*
289-
}
290-
)*) => ($(
291-
#[inline]
292-
$(#[$attr])*
293-
pub extern fn $i($($arg: $argty),*) -> $ret {
294-
$($body);*
295-
}
296-
)*)
249+
/// A nonpublic function that is const as long as `const-extern-fn` is enabled.
250+
macro_rules! const_fn {
251+
($(
252+
$(#[$attr:meta])*
253+
$({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),*) -> $ret:ty {
254+
$($body:stmt);*
297255
}
298-
299-
/// A nonpublic function that is const as long as `const-extern-fn` is enabled.
300-
macro_rules! const_fn {
301-
($(
302-
$(#[$attr:meta])*
303-
$({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),*) -> $ret:ty {
304-
$($body:stmt);*
305-
}
306-
)*) => ($(
307-
#[inline]
308-
$(#[$attr])*
309-
fn $i($($arg: $argty),*) -> $ret {
310-
$($body);*
311-
}
312-
)*)
256+
)*) => ($(
257+
#[inline]
258+
$(#[$attr])*
259+
$($constness)* fn $i($($arg: $argty),*) -> $ret {
260+
$($body);*
313261
}
314-
}
262+
)*)
315263
}
316264

317265
macro_rules! __item {

src/unix/bsd/apple/mod.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5522,18 +5522,9 @@ pub const VMADDR_CID_RESERVED: ::c_uint = 1;
55225522
pub const VMADDR_CID_HOST: ::c_uint = 2;
55235523
pub const VMADDR_PORT_ANY: ::c_uint = 0xFFFFFFFF;
55245524

5525-
cfg_if! {
5526-
if #[cfg(libc_const_extern_fn)] {
5527-
const fn __DARWIN_ALIGN32(p: usize) -> usize {
5528-
const __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::<u32>() - 1;
5529-
p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32
5530-
}
5531-
} else {
5532-
fn __DARWIN_ALIGN32(p: usize) -> usize {
5533-
const __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::<u32>() - 1;
5534-
p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32
5535-
}
5536-
}
5525+
const fn __DARWIN_ALIGN32(p: usize) -> usize {
5526+
const __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::<u32>() - 1;
5527+
p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32
55375528
}
55385529

55395530
pub const THREAD_EXTENDED_POLICY_COUNT: mach_msg_type_number_t =

src/unix/bsd/freebsdlike/freebsd/mod.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4902,16 +4902,8 @@ pub const TFD_TIMER_CANCEL_ON_SET: ::c_int = 0x02;
49024902

49034903
pub const CLOSE_RANGE_CLOEXEC: ::c_uint = 1 << 2;
49044904

4905-
cfg_if! {
4906-
if #[cfg(libc_const_extern_fn)] {
4907-
pub const fn MAP_ALIGNED(a: ::c_int) -> ::c_int {
4908-
a << 24
4909-
}
4910-
} else {
4911-
pub fn MAP_ALIGNED(a: ::c_int) -> ::c_int {
4912-
a << 24
4913-
}
4914-
}
4905+
pub const fn MAP_ALIGNED(a: ::c_int) -> ::c_int {
4906+
a << 24
49154907
}
49164908

49174909
const_fn! {

src/unix/bsd/netbsdlike/netbsd/mod.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,17 +2398,8 @@ pub const RB_STRING: ::c_int = 0x000000400;
23982398
pub const RB_POWERDOWN: ::c_int = RB_HALT | 0x000000800;
23992399
pub const RB_USERCONF: ::c_int = 0x000001000;
24002400

2401-
cfg_if! {
2402-
2403-
if #[cfg(libc_const_extern_fn)] {
2404-
pub const fn MAP_ALIGNED(alignment: ::c_int) -> ::c_int {
2405-
alignment << MAP_ALIGNMENT_SHIFT
2406-
}
2407-
} else {
2408-
pub fn MAP_ALIGNED(alignment: ::c_int) -> ::c_int {
2409-
alignment << MAP_ALIGNMENT_SHIFT
2410-
}
2411-
}
2401+
pub const fn MAP_ALIGNED(alignment: ::c_int) -> ::c_int {
2402+
alignment << MAP_ALIGNMENT_SHIFT
24122403
}
24132404

24142405
// net/route.h

tests/const_fn.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![cfg(libc_const_extern_fn)] // If this does not hold, the file is empty
2-
31
#[cfg(target_os = "linux")]
42
const _FOO: libc::c_uint = unsafe { libc::CMSG_SPACE(1) };
53
//^ if CMSG_SPACE is not const, this will fail to compile

0 commit comments

Comments
 (0)