尝试编译 Rust 会生成错误 E3080

问题描述 投票:0回答:1

尝试在项目中编译 bootkit 时 - https://github.com/memN0ps/redlotus-rs

I get the error - error[E0308]: mismatched types
  --> bootkit\src/main.rs:33:16
   |
33 | if let Some(message) = info.message() {
   | ^^^^^^^^^^^^^ -------------- this expression has type `PanicMessage<'_>`
   | |
   | expected `PanicMessage<'_>`, found `Option<_>`.
   |
   = note: expected struct `PanicMessage<'_>`
                found enum `Option<_>`

必须纠正错误的代码部分

#[panic_handler]
fn panic_handler(info: &core::panic::PanicInfo) -> ! {
    if let Some(location) = info.location() {
        log::error!(
            "[-] Panic in {} at ({}, {}):",
            location.file(),
            location.line(),
            location.column()
        );
        if let Some(message) = info.message() {
            log::error!("[-] {}", message);
        }
    }

    loop {}
}

rust compilation rust-cargo uefi
1个回答
0
投票

虽然它以前返回一个

Option
,但最近的
PanicInfo::message
,因为#115974直接返回一个
PanicMessage
,只需删除
if let
即可。

#[panic_handler]
fn panic_handler(info: &core::panic::PanicInfo) -> ! {
    if let Some(location) = info.location() {
        log::error!(
            "[-] Panic in {} at ({}, {}):",
            location.file(),
            location.line(),
            location.column()
        );
        let message = info.message();
        log::error!("[-] {}", message);
    }

    loop {}
}

不稳定的函数更改其签名的情况并不罕见,请始终确保检查文档的编译器版本。

© www.soinside.com 2019 - 2024. All rights reserved.