Skip to content

Commit 674cc1f

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 674cc1f

File tree

9 files changed

+20
-59
lines changed

9 files changed

+20
-59
lines changed

Cargo.toml

+3-1
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

+5-3
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

+1-18
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

-1
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

+4-1
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,11 @@ 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+
218+
// FIXME(ctest): ctest can't handle `const extern` functions, we should be able to remove this
219+
// cfg completely.
217220
cfg_if! {
218-
if #[cfg(libc_const_extern_fn)] {
221+
if #[cfg(feature = "const-extern-fn")] {
219222
/// Define an `unsafe` function that is const as long as `const-extern-fn` is enabled.
220223
macro_rules! f {
221224
($(

src/unix/bsd/apple/mod.rs

+3-12
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

+2-10
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

+2-11
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

-2
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)