Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main branch no longer implicitly enables const-extern-fn #3564

Open
n1000 opened this issue Jan 28, 2024 · 2 comments
Open

main branch no longer implicitly enables const-extern-fn #3564

n1000 opened this issue Jan 28, 2024 · 2 comments
Labels
C-bug Category: bug E-medium E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate.
Milestone

Comments

@n1000
Copy link

n1000 commented Jan 28, 2024

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 e2e6fd6 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 e2e6fd6). 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 e2e6fd6 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.

@n1000 n1000 added the C-bug Category: bug label Jan 28, 2024
@JohnTitor
Copy link
Member

JohnTitor commented Jan 28, 2024

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 #3248 for what is needed to release.

@bjorn3
Copy link
Member

bjorn3 commented May 31, 2024

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.

@tgross35 tgross35 added this to the 1.0 milestone Aug 29, 2024
@tgross35 tgross35 added the E-medium E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. label Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug E-medium E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate.
Projects
None yet
Development

No branches or pull requests

4 participants