小编ber*_*oal的帖子

为什么 `CMSG_SPACE` 不是 Rust 中的常量函数?

根据文档

pub const unsafe extern "C" fn CMSG_SPACE(length: c_uint) -> c_uint
Run Code Online (Sandbox Code Playgroud)

但是,如果我编译

fn main() {
    let _ = [0u8; libc::CMSG_SPACE(1) as usize];
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
 --> src/bin/libc-const.rs:2:27
  |
2 |     let _ = [0u8; unsafe {libc::CMSG_SPACE(1) as usize}];
  |                           ^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0015`.
Run Code Online (Sandbox Code Playgroud)

libc compile-time-constant rust

4
推荐指数
1
解决办法
141
查看次数

标签 统计

compile-time-constant ×1

libc ×1

rust ×1