Skip to content

Commit 24deb91

Browse files
authored
Merge pull request #1570 from chorman0773/spec-add-identifiers-crates-and-source-files
Add spec identifiers to crates-and-source-files.md
2 parents bff8721 + 1f3675c commit 24deb91

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

src/crates-and-source-files.md

+31-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Crates and source files
22

3+
r[crate]
4+
5+
r[crate.syntax]
36
> **<sup>Syntax</sup>**\
47
> _Crate_ :\
58
> &nbsp;&nbsp; [_InnerAttribute_]<sup>\*</sup>\
@@ -10,40 +13,52 @@
1013
> compiler, and the language has always been designed to be compiled. For these
1114
> reasons, this section assumes a compiler.
1215
16+
r[crate.compile-time]
1317
Rust's semantics obey a *phase distinction* between compile-time and
1418
run-time.[^phase-distinction] Semantic rules that have a *static
1519
interpretation* govern the success or failure of compilation, while
1620
semantic rules that have a *dynamic interpretation* govern the behavior of the
1721
program at run-time.
1822

23+
r[crate.unit]
1924
The compilation model centers on artifacts called _crates_. Each compilation
2025
processes a single crate in source form, and if successful, produces a single
2126
crate in binary form: either an executable or some sort of
2227
library.[^cratesourcefile]
2328

29+
r[crate.module]
2430
A _crate_ is a unit of compilation and linking, as well as versioning,
2531
distribution, and runtime loading. A crate contains a _tree_ of nested
2632
[module] scopes. The top level of this tree is a module that is
2733
anonymous (from the point of view of paths within the module) and any item
2834
within a crate has a canonical [module path] denoting its location
2935
within the crate's module tree.
3036

37+
r[crate.input-source]
3138
The Rust compiler is always invoked with a single source file as input, and
3239
always produces a single output crate. The processing of that source file may
3340
result in other source files being loaded as modules. Source files have the
3441
extension `.rs`.
3542

43+
r[crate.module-def]
3644
A Rust source file describes a module, the name and location of which &mdash;
3745
in the module tree of the current crate &mdash; are defined from outside the
3846
source file: either by an explicit [_Module_][module] item in a referencing
39-
source file, or by the name of the crate itself. Every source file is a
47+
source file, or by the name of the crate itself.
48+
49+
r[crate.inline-module]
50+
Every source file is a
4051
module, but not every module needs its own source file: [module
4152
definitions][module] can be nested within one file.
4253

54+
r[crate.items]
4355
Each source file contains a sequence of zero or more [_Item_] definitions, and
4456
may optionally begin with any number of [attributes]
4557
that apply to the containing module, most of which influence the behavior of
46-
the compiler. The anonymous crate module can have additional attributes that
58+
the compiler.
59+
60+
r[crate.attributes]
61+
The anonymous crate module can have additional attributes that
4762
apply to the crate as a whole.
4863

4964
> **Note**: The file's contents may be preceded by a [shebang].
@@ -62,8 +77,13 @@ apply to the crate as a whole.
6277

6378
## Main Functions
6479

65-
A crate that contains a `main` [function] can be compiled to an executable. If a
66-
`main` function is present, it must take no arguments, must not declare any
80+
r[crate.main]
81+
82+
r[crate.main.general]
83+
A crate that contains a `main` [function] can be compiled to an executable.
84+
85+
r[crate.main.restriction]
86+
If a `main` function is present, it must take no arguments, must not declare any
6787
[trait or lifetime bounds], must not have any [where clauses], and its return
6888
type must implement the [`Termination`] trait.
6989

@@ -81,6 +101,7 @@ fn main() -> impl std::process::Termination {
81101
}
82102
```
83103

104+
r[crate.main.import]
84105
The `main` function may be an import, e.g. from an external crate or from the current one.
85106

86107
```rust
@@ -105,19 +126,25 @@ use foo::bar as main;
105126

106127
### The `no_main` attribute
107128

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

112135
## The `crate_name` attribute
113136

137+
r[crate.crate_name]
138+
139+
r[crate.crate_name.general]
114140
The *`crate_name` [attribute]* may be applied at the crate level to specify the
115141
name of the crate with the [_MetaNameValueStr_] syntax.
116142

117143
```rust
118144
#![crate_name = "mycrate"]
119145
```
120146

147+
r[crate.crate_name.restriction]
121148
The crate name must not be empty, and must only contain [Unicode alphanumeric]
122149
or `_` (U+005F) characters.
123150

0 commit comments

Comments
 (0)