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

CMSG_SPACE should be const #2819

Closed
pacak opened this issue Jun 8, 2022 · 3 comments
Closed

CMSG_SPACE should be const #2819

pacak opened this issue Jun 8, 2022 · 3 comments
Labels
C-API-request Category: API request

Comments

@pacak
Copy link

pacak commented Jun 8, 2022

There was this: #2087 but since #2132 had no tests in it it either never worked or got broken at some point later:

use std::os::unix::prelude::RawFd;

const CONTROL_LEN: usize = unsafe { libc::CMSG_SPACE(std::mem::size_of::<RawFd>() as _) as _ };
t% cargo test
   Compiling libc v0.2.126
   Compiling asdf v0.1.0 (/home/pacak/rust/asdf)
error[E0015]: cannot call non-const fn `CMSG_SPACE` in constants
 --> src/lib.rs:3:37
  |
3 | const CONTROL_LEN: usize = unsafe { libc::CMSG_SPACE(std::mem::size_of::<RawFd>() as _) as _ };
  |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = 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 `asdff` due to previous error
warning: build failed, waiting for other jobs to finish...
error: build failed

rustc 1.60.0 (7737e0b5c 2022-04-04)

@pacak pacak added the C-API-request Category: API request label Jun 8, 2022
@JohnTitor
Copy link
Member

You have to enable the const-extern-fn feature of the crate.

@pacak
Copy link
Author

pacak commented Jun 8, 2022

I see, and it's nightly only. That's sad.

Thank you.

@pacak pacak closed this as completed Jun 8, 2022
@JohnTitor
Copy link
Member

I see, and it's nightly only. That's sad.

It'll be available from 1.62, thanks to rust-lang/rust#95346 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-API-request Category: API request
Projects
None yet
Development

No branches or pull requests

2 participants