You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/crates-and-source-files.md
+13-45Lines changed: 13 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,52 +12,28 @@ r[crate.syntax]
12
12
> Although Rust, like any other language, can be implemented by an interpreter as well as a compiler, the only existing implementation is a compiler, and the language has always been designed to be compiled. For these reasons, this section assumes a compiler.
13
13
14
14
r[crate.compile-time]
15
-
Rust's semantics obey a *phase distinction* between compile-time and
16
-
run-time.[^phase-distinction] Semantic rules that have a *static
17
-
interpretation* govern the success or failure of compilation, while
18
-
semantic rules that have a *dynamic interpretation* govern the behavior of the
19
-
program at run-time.
15
+
Rust's semantics obey a *phase distinction* between compile-time and run-time.[^phase-distinction] Semantic rules that have a *static interpretation* govern the success or failure of compilation, while semantic rules that have a *dynamic interpretation* govern the behavior of the program at run-time.
20
16
21
17
r[crate.unit]
22
-
The compilation model centers on artifacts called _crates_. Each compilation
23
-
processes a single crate in source form, and if successful, produces a single
24
-
crate in binary form: either an executable or some sort of
25
-
library.[^cratesourcefile]
18
+
The compilation model centers on artifacts called _crates_. Each compilation processes a single crate in source form, and if successful, produces a single crate in binary form: either an executable or some sort of library.[^cratesourcefile]
26
19
27
20
r[crate.module]
28
-
A _crate_ is a unit of compilation and linking, as well as versioning,
29
-
distribution, and runtime loading. A crate contains a _tree_ of nested
30
-
[module] scopes. The top level of this tree is a module that is
31
-
anonymous (from the point of view of paths within the module) and any item
32
-
within a crate has a canonical [module path] denoting its location
33
-
within the crate's module tree.
21
+
A _crate_ is a unit of compilation and linking, as well as versioning, distribution, and runtime loading. A crate contains a _tree_ of nested [module] scopes. The top level of this tree is a module that is anonymous (from the point of view of paths within the module) and any item within a crate has a canonical [module path] denoting its location within the crate's module tree.
34
22
35
23
r[crate.input-source]
36
-
The Rust compiler is always invoked with a single source file as input, and
37
-
always produces a single output crate. The processing of that source file may
38
-
result in other source files being loaded as modules. Source files have the
39
-
extension `.rs`.
24
+
The Rust compiler is always invoked with a single source file as input, and always produces a single output crate. The processing of that source file may result in other source files being loaded as modules. Source files have the extension `.rs`.
40
25
41
26
r[crate.module-def]
42
-
A Rust source file describes a module, the name and location of which —
43
-
in the module tree of the current crate — are defined from outside the
44
-
source file: either by an explicit [Module][grammar-Module] item in a referencing
45
-
source file, or by the name of the crate itself.
27
+
A Rust source file describes a module, the name and location of which — in the module tree of the current crate — are defined from outside the source file: either by an explicit [Module][grammar-Module] item in a referencing source file, or by the name of the crate itself.
46
28
47
29
r[crate.inline-module]
48
-
Every source file is a
49
-
module, but not every module needs its own source file: [module
50
-
definitions][module] can be nested within one file.
30
+
Every source file is a module, but not every module needs its own source file: [module definitions][module] can be nested within one file.
51
31
52
32
r[crate.items]
53
-
Each source file contains a sequence of zero or more [Item] definitions, and
54
-
may optionally begin with any number of [attributes]
55
-
that apply to the containing module, most of which influence the behavior of
56
-
the compiler.
33
+
Each source file contains a sequence of zero or more [Item] definitions, and may optionally begin with any number of [attributes] that apply to the containing module, most of which influence the behavior of the compiler.
57
34
58
35
r[crate.attributes]
59
-
The anonymous crate module can have additional attributes that
60
-
apply to the crate as a whole.
36
+
The anonymous crate module can have additional attributes that apply to the crate as a whole.
61
37
62
38
> [!NOTE]
63
39
> The file's contents may be preceded by a [shebang].
@@ -81,9 +57,7 @@ r[crate.main.general]
81
57
A crate that contains a `main`[function] can be compiled to an executable.
82
58
83
59
r[crate.main.restriction]
84
-
If a `main` function is present, it must take no arguments, must not declare any
85
-
[trait or lifetime bounds], must not have any [where clauses], and its return
86
-
type must implement the [`Termination`] trait.
60
+
If a `main` function is present, it must take no arguments, must not declare any [trait or lifetime bounds], must not have any [where clauses], and its return type must implement the [`Termination`] trait.
87
61
88
62
```rust
89
63
fnmain() {}
@@ -139,24 +113,18 @@ r[crate.crate_name]
139
113
## The `crate_name` attribute
140
114
141
115
r[crate.crate_name.general]
142
-
The *`crate_name`[attribute]* may be applied at the crate level to specify the
143
-
name of the crate with the [MetaNameValueStr] syntax.
116
+
The *`crate_name`[attribute]* may be applied at the crate level to specify the name of the crate with the [MetaNameValueStr] syntax.
144
117
145
118
```rust
146
119
#![crate_name ="mycrate"]
147
120
```
148
121
149
122
r[crate.crate_name.restriction]
150
-
The crate name must not be empty, and must only contain [Unicode alphanumeric]
151
-
or `_` (U+005F) characters.
123
+
The crate name must not be empty, and must only contain [Unicode alphanumeric] or `_` (U+005F) characters.
152
124
153
-
[^phase-distinction]: This distinction would also exist in an interpreter.
154
-
Static checks like syntactic analysis, type checking, and lints should
155
-
happen before the program is executed regardless of when it is executed.
125
+
[^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.
156
126
157
-
[^cratesourcefile]: A crate is somewhat analogous to an *assembly* in the
158
-
ECMA-335 CLI model, a *library* in the SML/NJ Compilation Manager, a *unit*
159
-
in the Owens and Flatt module system, or a *configuration* in Mesa.
127
+
[^cratesourcefile]: A crate is somewhat analogous to an *assembly* in the ECMA-335 CLI model, a *library* in the SML/NJ Compilation Manager, a *unit* in the Owens and Flatt module system, or a *configuration* in Mesa.
0 commit comments