Skip to content

Commit d1f046f

Browse files
frewsxcvsteveklabnik
authored andcommitted
Crates and source files
1 parent cdcc0f3 commit d1f046f

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/doc/reference/src/crates-and-source-files.md

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,16 @@ semantic rules
1313
that have a *dynamic interpretation* govern the behavior of the program at
1414
run-time.
1515

16-
[^phase-distinction]: This distinction would also exist in an interpreter.
17-
Static checks like syntactic analysis, type checking, and lints should
18-
happen before the program is executed regardless of when it is executed.
19-
2016
The compilation model centers on artifacts called _crates_. Each compilation
2117
processes a single crate in source form, and if successful, produces a single
2218
crate in binary form: either an executable or some sort of
2319
library.[^cratesourcefile]
2420

25-
[^cratesourcefile]: A crate is somewhat analogous to an *assembly* in the
26-
ECMA-335 CLI model, a *library* in the SML/NJ Compilation Manager, a *unit*
27-
in the Owens and Flatt module system, or a *configuration* in Mesa.
28-
2921
A _crate_ is a unit of compilation and linking, as well as versioning,
3022
distribution and runtime loading. A crate contains a _tree_ of nested
31-
[module](#modules) scopes. The top level of this tree is a module that is
23+
[module] scopes. The top level of this tree is a module that is
3224
anonymous (from the point of view of paths within the module) and any item
33-
within a crate has a canonical [module path](#paths) denoting its location
25+
within a crate has a canonical [module path] denoting its location
3426
within the crate's module tree.
3527

3628
The Rust compiler is always invoked with a single source file as input, and
@@ -42,16 +34,16 @@ A Rust source file describes a module, the name and location of which —
4234
in the module tree of the current crate — are defined from outside the
4335
source file: either by an explicit `mod_item` in a referencing source file, or
4436
by the name of the crate itself. Every source file is a module, but not every
45-
module needs its own source file: [module definitions](#modules) can be nested
37+
module needs its own source file: [module definitions][module] can be nested
4638
within one file.
4739

4840
Each source file contains a sequence of zero or more `item` definitions, and
49-
may optionally begin with any number of [attributes](#items-and-attributes)
41+
may optionally begin with any number of [attributes]
5042
that apply to the containing module, most of which influence the behavior of
5143
the compiler. The anonymous crate module can have additional attributes that
5244
apply to the crate as a whole.
5345

54-
```no_run
46+
```rust,no_run
5547
// Specify the crate name.
5648
#![crate_name = "projx"]
5749
@@ -65,4 +57,17 @@ apply to the crate as a whole.
6557

6658
A crate that contains a `main` function can be compiled to an executable. If a
6759
`main` function is present, its return type must be `()`
68-
("[unit](#tuple-types)") and it must take no arguments.
60+
("[unit]") and it must take no arguments.
61+
62+
[^phase-distinction]: This distinction would also exist in an interpreter.
63+
Static checks like syntactic analysis, type checking, and lints should
64+
happen before the program is executed regardless of when it is executed.
65+
66+
[^cratesourcefile]: A crate is somewhat analogous to an *assembly* in the
67+
ECMA-335 CLI model, a *library* in the SML/NJ Compilation Manager, a *unit*
68+
in the Owens and Flatt module system, or a *configuration* in Mesa.
69+
70+
[module]: items.html#modules
71+
[module path]: paths.html
72+
[attributes]: items-and-attributes.html
73+
[unit]: types.html#tuple-types

0 commit comments

Comments
 (0)