`panic_handler` can be an `unsafe fn`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
This issue is a variant of #134225. I am filing this issue on behalf of @zesterer, who discovered this.
This code currently compiles:
#![no_std]
#[panic_handler]
unsafe fn handle(_: &core::panic::PanicInfo) -> ! {
loop {}
}
Presumably, this causes this unsafe function to be called if a panic happens. This is unsound, as this calls an unsafe function without considering its safety requirements.
Cursory github search for code that relies on this compiling: https://github.com/search?q=language%3Arust+%2F%23%5C%5Bpanic_handler%5C%5D%5Cnunsafe%2F&type=code
Meta
Reproducible on the playground with version 1.100.0-nightly (2026-09-17 330d317121e16b5db8e5)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example in the playground with the reported nightly version, then read issue #134225 and trace the compiler handling for the #[panic_handler] attribute. The fix is complete when an unsafe panic handler is no longer accepted without accounting for its safety requirements, with regression coverage for this example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100