这是预期的行为还是编译器错误?
以下代码无法编译。valuesinMyStruct是一个Option因为Vec::new不是 const fn - 但它Option::None是常量(但它仍然不能编译)。
type MyFun = fn(input: u32) -> u32;
struct MyStruct {
values: Option<Vec<MyFun>>,
}
impl MyStruct {
pub const fn init() -> Self {
Self { values: None }
}
}
fn main() {
MyStruct::init();
}
Run Code Online (Sandbox Code Playgroud)
error[E0723]: function pointers in const fn are unstable
--> src/main.rs:9:24
|
9 | Self { values: None }
| ^^^^
|
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for …Run Code Online (Sandbox Code Playgroud)