尝试编译此 bootkit 项目时,出现错误:
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 {}
}
以前返回的是
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 {}
}
不稳定的函数更改其签名的情况并不罕见,请务必检查文档的编译器版本以避免此类混淆。