Skip to content

Book tutorial results in panic: unreachable_unchecked must never be reached #1713

Open
@jhwgh1968

Description

@jhwgh1968

I tried this code:

I followed the instructions of the Rust UEFI book precisely in the Tutorial chapter (which means I am using the current stable crates.io version):

#![no_main]
#![no_std]

use log::info;
use uefi::prelude::*;

#[entry]
fn main() -> Status {
    uefi::helpers::init().unwrap();
    info!("Hello world!");
    boot::stall(10_000_000);
    Status::SUCCESS
}

With the sole exception that the OVMF version I'm using renamed its files for x64 to OVMF_CODE.4m.fd and OVMF_VARS.4m.fd respectively. But everything seemed to work on the QEMU side.

I expected this to happen: the example application to run as shown in the book.

Instead, this happened: I got the following output (manually retyped so whitespace may not be accuate) and after several seconds of sleep, the VM turned itself off as expected.

[ INFO]:            [PANIC]: panicked at library/core/src/panicking.rs:218:5
unsafe precondition(s) violated: hint:unreachable_unchecked must never be reached

This indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety.

Software and Hardware

QEMU emulator version 10.0.0
Copyright (c) 2003-2025 Fabrice Bellard and the QEMU Project developers

Arch Linux:
edk2-ovmf 202411-1
linux 6.12.4-arch1-1
extra/qemu-system-x86 10.0.0-5

CPU:
vendor_id : AuthenticAMD
cpu family : 25
model : 33
model name : AMD Ryzen 9 5950X 16-Core Processor

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions