Skip to content

How to define panic_fmt is not documented well #33677

Closed
@habnabit

Description

@habnabit

This includes on https://doc.rust-lang.org/book/no-stdlib.html and https://doc.rust-lang.org/core/. The former has an incorrect signature on panic_fmt and the latter doesn't mention that you need a #[lang] annotation. The relationship between panic_fmt and rust_begin_unwind (the former is a lang item, and the latter is a symbol that the former produces) has been confusing people on #rust recently, and should probably be documented as well.

For reference, the correct way to define it is:

#[lang="panic_fmt"]
#[unwind]
extern fn panic_fmt(args: ::core::fmt::Arguments, file: &'static str, line: u32) -> ! {
    // ...
}

Every part of that signature (except the function name) is necessary; any omission can cause unclear or misleading errors, or lead to the function being called with the wrong ABI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions