gpt4 book ai didi

rust - 在显式初始化结构成员时获取 "use of possibly uninitialized variable"

转载 作者:行者123 更新时间:2023-11-29 08:35:59 25 4
gpt4 key购买 nike

这是我遇到的错误:

error[E0381]: use of possibly uninitialized variable: `mbinfo.flags`
--> kernel/src/loader/mod.rs:256:20
|
256 | mbinfo.flags = mbinfo.flags | multiboot::MULTIBOOT_INFO_CMDLINE;
| ^^^^^^^^^^^^ use of possibly uninitialized `mbinfo.flags`

这是代码:

let mut mbinfo: multiboot::multiboot_info;
mbinfo.flags = 0 as u32;
mbinfo.flags = mbinfo.flags | multiboot::MULTIBOOT_INFO_CMDLINE

即使我明确地初始化了它,我还是收到了错误。我试过使结构派生默认值,但问题是该结构包含联合,当我尝试派生默认值时,我得到

error: this trait cannot be derived for unions 

有什么简单的出路吗?谢谢。

多重引导模块是由 bindgen 从头文件自动生成的。

MWE on Rust Playground,代码在最后:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=464b7fb21fc75a54618b14619076d152

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com