Skip to content

Commit 576f778

Browse files
committed
Enable libc_const_extern_fn implicitly from Rust 1.62
1 parent e534fd8 commit 576f778

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
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;

0 commit comments

Comments
 (0)