Skip to content

Update no_main to use the attribute template #1901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/crates-and-source-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,27 @@ For more information, see the [panic documentation][panic-docs].
r[crate.no_main]
### The `no_main` attribute

r[crate.no_main.intro]
The *`no_main` [attribute]* may be applied at the crate level to disable emitting the `main` symbol for an executable binary. This is useful when some other object being linked to defines `main`.

> [!EXAMPLE]
> <!-- ignore: does not work with test framework -->
> ```rust,ignore
> #![no_main]
> ```

r[crate.no_main.syntax]
The `no_main` attribute uses the [MetaWord] syntax and thus does not take any inputs.

r[crate.no_main.allowed-positions]
The `no_main` attribute may only be applied to the crate root.

r[crate.no_main.duplicates]
Duplicate instances of the `no_main` attribute are ignored.

> [!NOTE]
> `rustc` current warns about unused duplicate `no_main` attributes.

r[crate.crate_name]
## The `crate_name` attribute

Expand Down