From c6b23d4221fed7a520d92ab7e30daf3b5dcb8f3d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 20 Jun 2025 17:39:43 -0700 Subject: [PATCH 1/2] Update crate_name to use the attribute template --- src/crates-and-source-files.md | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/crates-and-source-files.md b/src/crates-and-source-files.md index ed16044fd4..766d7f01f3 100644 --- a/src/crates-and-source-files.md +++ b/src/crates-and-source-files.md @@ -112,14 +112,27 @@ The *`no_main` [attribute]* may be applied at the crate level to disable emittin r[crate.crate_name] ## The `crate_name` attribute -r[crate.crate_name.general] -The *`crate_name` [attribute]* may be applied at the crate level to specify the name of the crate with the [MetaNameValueStr] syntax. +r[crate.crate_name.intro] +The *`crate_name` [attribute]* specifies the name of the crate. -```rust -#![crate_name = "mycrate"] -``` +> [!EXAMPLE] +> ```rust +> #![crate_name = "mycrate"] +> ``` + +r[crate.crate_name.syntax] +The `crate_name` attribute uses the [MetaNameValueStr] syntax to specify the name of the crate. + +r[crate.crate_name.allowed-positions] +The `crate_name` attribute may only be applied to the crate root. + +r[crate.crate_name.duplicates] +Only the first `crate_name` attribute is used to determine the crate name. + +> [!NOTE] +> `rustc` currently warns on following duplicate `crate_name` attributes. This may become an error in the future. -r[crate.crate_name.restriction] +r[crate.crate_name.required-format] The crate name must not be empty, and must only contain [Unicode alphanumeric] or `_` (U+005F) characters. [^phase-distinction]: This distinction would also exist in an interpreter. Static checks like syntactic analysis, type checking, and lints should happen before the program is executed regardless of when it is executed. From d4a5452c9550b88e40fba2f4002d8d69d169d55f Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 22 Sep 2025 13:09:04 -0700 Subject: [PATCH 2/2] Add template attribute comment to crate_name --- src/crates-and-source-files.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/crates-and-source-files.md b/src/crates-and-source-files.md index 766d7f01f3..9f76add8a7 100644 --- a/src/crates-and-source-files.md +++ b/src/crates-and-source-files.md @@ -109,6 +109,8 @@ r[crate.no_main] 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`. + + r[crate.crate_name] ## The `crate_name` attribute