为什么 `CMSG_SPACE` 在 Rust 中不是一个常量函数?

4
根据文档
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`.
1个回答

6
libcconst-extern-fn功能需要激活才能使此函数成为const。在docs.rs文档中记录的版本已启用了该功能,这就是为什么它默认情况下显示为const(不幸的原因)。该功能需要使用夜间版rustc。详情

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接