【问题标题】:Why is `CMSG_SPACE` not a constant function in Rust?为什么 `CMSG_SPACE` 在 Rust 中不是一个常量函数?
【发布时间】:2021-11-05 13:48:29
【问题描述】:

根据the documentation

pub const unsafe extern "C" fn CMSG_SPACE(length: c_uint) -> c_uint

但是,如果我编译

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

我收到以下错误:

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`.

【问题讨论】:

    标签: rust libc compile-time-constant


    【解决方案1】:

    const-extern-fn featurelibc is required 激活此功能为constdocs.rs 上记录的版本启用了此功能,这就是为什么它(不幸地)默认显示为 const。此功能需要夜间 rustc。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-26
      • 2019-11-13
      • 1970-01-01
      • 2019-06-05
      相关资源
      最近更新 更多