Skip to content

Commit 4042ce2

Browse files
committed
Auto merge of #2820 - JohnTitor:1-62-const-extern-fn, r=Amanieu
Enable `libc_const_extern_fn` implicitly from Rust 1.62 const_extern_fn for "C" has been stabilized since 1.62: rust-lang/rust#95346 This enables the const-extern-fn feature implicitly from 1.62, but leaves the crate feature as-is for compatibility and old nightlies. Closes #2785
2 parents bbf43e8 + 4a84f34 commit 4042ce2

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ libc = "0.2"
3535
This feature derives `Debug`, `Eq`, `Hash`, and `PartialEq`.
3636

3737
* `const-extern-fn`: Changes some `extern fn`s into `const extern fn`s.
38-
This feature requires a nightly rustc.
38+
If you use Rust >= 1.62, this feature is implicitly enabled.
39+
Otherwise it requires a nightly rustc.
3940

4041
* **deprecated**: `use_std` is deprecated, and is equivalent to `std`.
4142

@@ -53,6 +54,7 @@ newer Rust features are only available on newer Rust toolchains:
5354
| `core::ffi::c_void` | 1.30.0 |
5455
| `repr(packed(N))` | 1.33.0 |
5556
| `cfg(target_vendor)` | 1.33.0 |
57+
| `const-extern-fn` | 1.62.0 |
5658

5759
## Platform support
5860

build.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,18 @@ fn main() {
9797
println!("cargo:rustc-cfg=libc_thread_local");
9898
}
9999

100-
if const_extern_fn_cargo_feature {
101-
if !is_nightly || rustc_minor_ver < 40 {
102-
panic!("const-extern-fn requires a nightly compiler >= 1.40")
103-
}
100+
// Rust >= 1.62.0 allows to use `const_extern_fn` for "Rust" and "C".
101+
if rustc_minor_ver >= 62 {
104102
println!("cargo:rustc-cfg=libc_const_extern_fn");
103+
} else {
104+
// Rust < 1.62.0 requires a crate feature and feature gate.
105+
if const_extern_fn_cargo_feature {
106+
if !is_nightly || rustc_minor_ver < 40 {
107+
panic!("const-extern-fn requires a nightly compiler >= 1.40");
108+
}
109+
println!("cargo:rustc-cfg=libc_const_extern_fn_unstable");
110+
println!("cargo:rustc-cfg=libc_const_extern_fn");
111+
}
105112
}
106113
}
107114

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
feature = "rustc-dep-of-std",
3131
feature(native_link_modifiers, native_link_modifiers_bundle)
3232
)]
33-
#![cfg_attr(libc_const_extern_fn, feature(const_extern_fn))]
33+
#![cfg_attr(libc_const_extern_fn_unstable, feature(const_extern_fn))]
3434

3535
#[macro_use]
3636
mod macros;

src/unix/bsd/apple/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4682,6 +4682,16 @@ cfg_if! {
46824682
const __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::<u32>() - 1;
46834683
p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32
46844684
}
4685+
} else {
4686+
fn __DARWIN_ALIGN32(p: usize) -> usize {
4687+
let __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::<u32>() - 1;
4688+
p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32
4689+
}
4690+
}
4691+
}
4692+
4693+
cfg_if! {
4694+
if #[cfg(libc_const_size_of)] {
46854695
pub const THREAD_EXTENDED_POLICY_COUNT: mach_msg_type_number_t =
46864696
(::mem::size_of::<thread_extended_policy_data_t>() / ::mem::size_of::<integer_t>())
46874697
as mach_msg_type_number_t;
@@ -4722,10 +4732,6 @@ cfg_if! {
47224732
(::mem::size_of::<vm_statistics64_data_t>() / ::mem::size_of::<integer_t>())
47234733
as mach_msg_type_number_t;
47244734
} else {
4725-
fn __DARWIN_ALIGN32(p: usize) -> usize {
4726-
let __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::<u32>() - 1;
4727-
p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32
4728-
}
47294735
pub const THREAD_EXTENDED_POLICY_COUNT: mach_msg_type_number_t = 1;
47304736
pub const THREAD_TIME_CONSTRAINT_POLICY_COUNT: mach_msg_type_number_t = 4;
47314737
pub const THREAD_PRECEDENCE_POLICY_COUNT: mach_msg_type_number_t = 1;

0 commit comments

Comments
 (0)