Skip to content

Update crate_name to use the attribute template #1906

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 2 commits 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
29 changes: 20 additions & 9 deletions src/crates-and-source-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,28 @@ 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]
The crate name must not be empty, and must only contain [Unicode alphanumeric]
or `_` (U+005F) characters.
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
Expand Down