From 9f9e8f0b88c8bf115503eedbfd09743e7e3ebf8c Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 20 Jun 2025 17:25:07 -0700 Subject: [PATCH 1/2] Update no_main to use the attribute template --- src/crates-and-source-files.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/crates-and-source-files.md b/src/crates-and-source-files.md index e43c06e4d0..5ccb890fa4 100644 --- a/src/crates-and-source-files.md +++ b/src/crates-and-source-files.md @@ -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] +> +> ```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 From ebc70f233b6ec12a88381f449b88ec104cb5a99d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 22 Sep 2025 13:07:42 -0700 Subject: [PATCH 2/2] Minor update of `no_main` More closely align with the template, and some minor word tweaks. --- src/crates-and-source-files.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/crates-and-source-files.md b/src/crates-and-source-files.md index 5ccb890fa4..9fd919da64 100644 --- a/src/crates-and-source-files.md +++ b/src/crates-and-source-files.md @@ -130,6 +130,7 @@ When a "foreign" unwind (e.g. an exception thrown from C++ code, or a `panic!` i For more information, see the [panic documentation][panic-docs]. + r[crate.no_main] ### The `no_main` attribute @@ -143,16 +144,16 @@ The *`no_main` [attribute]* may be applied at the crate level to disable emittin > ``` r[crate.no_main.syntax] -The `no_main` attribute uses the [MetaWord] syntax and thus does not take any inputs. +The `no_main` attribute uses the [MetaWord] syntax. 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. +The `no_main` attribute may be used any number of times on the crate root. > [!NOTE] -> `rustc` current warns about unused duplicate `no_main` attributes. +> `rustc` lints against any use following the first. r[crate.crate_name] ## The `crate_name` attribute