libc
libc copied to clipboard
main branch no longer implicitly enables const-extern-fn
Rust / System details:
$ rustc -vV
rustc 1.75.0 (82e1608df 2023-12-21)
binary: rustc
commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112
commit-date: 2023-12-21
host: x86_64-unknown-linux-gnu
release: 1.75.0
LLVM version: 17.0.6
libc version: main branch at commit e2e6fd69f49925f95fd6b493217a7e44ef7564cd or later.
Minimal test code:
use libc::WIFEXITED;
fn main() {
const _: () = assert!(WIFEXITED(0));
}
Build output:
$ cargo build
Compiling libc-const-extern-test v0.1.0 (/home/nathan/src/libc-const-extern-test)
error[E0015]: cannot call non-const fn `WIFEXITED` in constants
--> src/main.rs:4:27
|
4 | const _: () = assert!(WIFEXITED(0));
| ^^^^^^^^^^^^
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
For more information about this error, try `rustc --explain E0015`.
error: could not compile `libc-const-extern-test` (bin "libc-const-extern-test") due to previous error
zsh: exit 101 cargo build
I wasn't sure if this was intended behavior or not (this error first showed up after commit e2e6fd69f49925f95fd6b493217a7e44ef7564cd). If it is intended, then I guess it is just the README.md that may need to be updated to remove this text from the Features description:
const-extern-fn: ... If you use Rust >= 1.62, this feature is implicitly enabled. ...
If it is unintended, then should the const-extern-fn
feature be enabled by default now that the MSRV of libc is 1.71?
In commit e2e6fd69f49925f95fd6b493217a7e44ef7564cd the definition of safe_f!
in src/macros.rs
was updated to be conditional on const-extern-fn
directly. Previously it was conditionally defined based on libc_const_extern_fn
which is automatically turned on by build.rs
based on the rustc version.
Apologies in advance if this is a known breakage / work in progress on main
.
Yeah, it's WIP. I'd like to enable it unconditionally but ctest2 emits an error which is used by libc-test. That's because it uses an ancient rustc parser and we have to make it update (and enable the const fn feature) before releasing libc v0.3. See https://github.com/rust-lang/libc/issues/3248 for what is needed to release.
Looks like there is both feature = "const-extern-fn"
which the user can enable and cfg(libc_const_extern_fn)
which the build script automatically enables. The latter is entirely unused in the source code.