Skip to content

panic_handler can be an unsafe fn #162967

Description

@theemathas

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)

Activity

  1. added
    A-attributesArea: Attributes (`#[…]`, `#![…]`)
    T-langRelevant to the language team
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
    C-bugCategory: This is a bug.
    A-panicArea: Panicking machinery
    on Sep 18, 2026
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Sep 18, 2026
  3. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 18, 2026
  4. bjorn3 commented on Sep 18, 2026

    @bjorn3
    Member

    #159016 would deny this if it lands.

  5. removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Sep 21, 2026
  6. rustbot commented on Sep 21, 2026

    @rustbot
    Collaborator

    Assigning P-high (discussion on Zulip)

  7. added a commit that references this issue on Oct 4, 2026
  8. added a commit that references this issue on Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)A-panicArea: Panicking machineryC-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions