Skip to content

Diagnostic for duplicate #[panic_handler] shouldn't talk about lang items #101764

@jonas-schievink

Description

@jonas-schievink

Given the following code:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=eda11ad1f58bb9579e1a515f26b30846

#![no_std]
#![no_main]

use core::panic::PanicInfo;

#[panic_handler]
fn panik(_: &PanicInfo) -> ! {
    loop {}
}

#[panic_handler]
fn panik2(_: &PanicInfo) -> ! {
    loop {}
}

The current output is:

error[E0152]: found duplicate lang item `panic_impl`
  --> src/lib.rs:12:1
   |
12 | fn panik2(_: &PanicInfo) -> ! {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: the lang item is first defined here
  --> src/lib.rs:7:1
   |
7  | fn panik(_: &PanicInfo) -> ! {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0152`.

"lang items" are an internal, perma-unstable implementation detail and should not be mentioned in this error message.

The error should probably also suggest a resolution, namely removing one of the panic handler functions.

This error is hit fairly often by people new to bare-metal Rust.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions