Skip to content

no_std entrypoint diagnostic suggests invalid #[no_mangle] syntax in Edition 2024 #160052

Description

@mousecrusher2

Code

#![no_std]

use core::panic::PanicInfo;

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

fn main() {}

Current output

error: using `fn main` requires the standard library
  |
  = help: use `#![no_main]` to bypass the Rust generated entrypoint and declare a platform specific entrypoint yourself, usually with `#[no_mangle]`

error: aborting due to 1 previous error

Desired output

error: using `fn main` requires the standard library
  |
  = help: use `#![no_main]` to bypass the Rust generated entrypoint and declare a platform specific entrypoint yourself, usually with `#[unsafe(no_mangle)]`

error: aborting due to 1 previous error

Rationale and extra context

In Edition 2024, the no_mangle attribute must be written using the unsafe-attribute syntax:
#[unsafe(no_mangle)]

The current diagnostic therefore suggests syntax that is rejected under the edition being compiled.

I compiled with:

rustc --edition=2024 -C panic=abort repro.rs

#[unsafe(no_mangle)] is also supported in earlier editions, so the diagnostic should be able to use this spelling unconditionally rather than branching based on the crate edition.

Other cases

Rust Version

$ rustc --version --verbose
rustc 1.97.1 (8bab26f4f 2026-07-14)
binary: rustc
commit-hash: 8bab26f4f68e0e26f0bb7960be334d5b520ea452
commit-date: 2026-07-14
host: x86_64-pc-windows-msvc
release: 1.97.1
LLVM version: 22.1.6

Anything else?

No response

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions