Skip to content

Suggest #[unsafe(no_mangle)] for entry points in no_std binaries - #163559

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
simonether:no-std-no-mangle-help
Oct 1, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
simonether:no-std-no-mangle-help

Conversation

@simonether

@simonether simonether commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #160052

The help for "using fn main requires the standard library" told users to declare their own entry point with #[no_mangle], which is an error in edition 2024. It now suggests #[unsafe(no_mangle)]. rustc has accepted that form in every edition since 1.82 (#128771), so the help does not need to depend on the edition.

The help keeps the bracketed form rather than naming the attribute in words (mejrs's suggestion), because it shows text the user writes verbatim. This follows nnethercote's comment, and rustc_lint already does the same (diagnostics.rs).

I updated the expected output of the UI test, and tidy passes. I have not built the compiler locally, so the UI test will first run in CI.

cc @mejrs @nnethercote

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 30, 2026
@rustbot

rustbot commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @tiif (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 77 candidates
  • Random selection from 21 candidates

@nnethercote

Copy link
Copy Markdown
Contributor

Thanks for the fix!

@bors r+ rollup

@rust-bors

rust-bors Bot commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 1eb5c52 has been approved by nnethercote

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 30, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 1, 2026
Rollup of 20 pull requests

Successful merges:

 - #163279 (const and NonZero impl for clamp_magnitude())
 - #163081 (Provide more context on "not general enough" error)
 - #163455 (Don't use the metadata based crate_hash for rustdoc runs)
 - #159798 (Attribute documentation for cfg_attr)
 - #162921 (make mips64 `Complex` GCC-compatible)
 - #163368 (Don't build format string suggestions from `concat!` offsets)
 - #163375 (Update expect messages in library/std/src/os/unix/net/ following Rust's `expect` guidance)
 - #163470 (Miscellaneous attr error stuff)
 - #163489 (expose Rc::is_unique)
 - #163492 (x86 and x86_64: cleanup some callconv code)
 - #163496 (cycle handling: mirror old solver)
 - #163509 (Use more default field values in `Resolver`)
 - #163519 (Forbid  `Reborrow` impls for types with destructors)
 - #163520 (Cast cleanups)
 - #163524 (Document `Result` case for the `arena_cache` query modifier)
 - #163546 (PassWrapper: adapt for new PassPlugin load method)
 - #163551 (Add libs-nominated triagebot config)
 - #163559 (Suggest `#[unsafe(no_mangle)]` for entry points in `no_std` binaries)
 - #163564 (rustc-dev-guide subtree update)
 - #163568 (remove dead cfg_select! arm)
@rust-bors
rust-bors Bot merged commit 4f27b89 into rust-lang:main Oct 1, 2026
13 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 1, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 1, 2026
Rollup merge of #163559 - simonether:no-std-no-mangle-help, r=nnethercote

Suggest `#[unsafe(no_mangle)]` for entry points in `no_std` binaries

Fixes #160052

The help for "using `fn main` requires the standard library" told users to declare their own entry point with `#[no_mangle]`, which is an error in edition 2024. It now suggests `#[unsafe(no_mangle)]`. rustc has accepted that form in every edition since 1.82 (#128771), so the help does not need to depend on the edition.

The help keeps the bracketed form rather than naming the attribute in words (mejrs's suggestion), because it shows text the user writes verbatim. This follows [nnethercote's comment](#160052 (comment)), and `rustc_lint` already does the same ([diagnostics.rs](https://github.com/rust-lang/rust/blob/1625626af12c1f95540530c6fc1242ff10aaba0a/compiler/rustc_lint/src/diagnostics.rs#L950)).

I updated the expected output of the UI test, and tidy passes. I have not built the compiler locally, so the UI test will first run in CI.
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Oct 1, 2026
Rollup of 20 pull requests

Successful merges:

 - rust-lang/rust#163279 (const and NonZero impl for clamp_magnitude())
 - rust-lang/rust#163081 (Provide more context on "not general enough" error)
 - rust-lang/rust#163455 (Don't use the metadata based crate_hash for rustdoc runs)
 - rust-lang/rust#159798 (Attribute documentation for cfg_attr)
 - rust-lang/rust#162921 (make mips64 `Complex` GCC-compatible)
 - rust-lang/rust#163368 (Don't build format string suggestions from `concat!` offsets)
 - rust-lang/rust#163375 (Update expect messages in library/std/src/os/unix/net/ following Rust's `expect` guidance)
 - rust-lang/rust#163470 (Miscellaneous attr error stuff)
 - rust-lang/rust#163489 (expose Rc::is_unique)
 - rust-lang/rust#163492 (x86 and x86_64: cleanup some callconv code)
 - rust-lang/rust#163496 (cycle handling: mirror old solver)
 - rust-lang/rust#163509 (Use more default field values in `Resolver`)
 - rust-lang/rust#163519 (Forbid  `Reborrow` impls for types with destructors)
 - rust-lang/rust#163520 (Cast cleanups)
 - rust-lang/rust#163524 (Document `Result` case for the `arena_cache` query modifier)
 - rust-lang/rust#163546 (PassWrapper: adapt for new PassPlugin load method)
 - rust-lang/rust#163551 (Add libs-nominated triagebot config)
 - rust-lang/rust#163559 (Suggest `#[unsafe(no_mangle)]` for entry points in `no_std` binaries)
 - rust-lang/rust#163564 (rustc-dev-guide subtree update)
 - rust-lang/rust#163568 (remove dead cfg_select! arm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants