Skip to content

CMSG_SPACE should be const #2819

Closed
Closed
@pacak

Description

@pacak

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions