@@ -735,15 +735,26 @@ Rust syntax is restricted in two ways:
735
735
736
736
# Crates and source files
737
737
738
- Rust is a * compiled* language. Its semantics obey a * phase distinction* between
739
- compile-time and run-time. Those semantic rules that have a * static
738
+ Although Rust, like any other language, can be implemented by an interpreter as
739
+ well as a compiler, the only existing implementation is a compiler &mdash ;
740
+ from now on referred to as * the* Rust compiler &mdash ; and the language has
741
+ always been designed to be compiled. For these reasons, this section assumes a
742
+ compiler.
743
+
744
+ Rust's semantics obey a * phase distinction* between compile-time and
745
+ run-time.[ ^ phase-distinction ] Those semantic rules that have a * static
740
746
interpretation* govern the success or failure of compilation. Those semantics
741
747
that have a * dynamic interpretation* govern the behavior of the program at
742
748
run-time.
743
749
750
+ [ ^ phase-distinction ] : This distinction would also exist in an interpreter.
751
+ Static checks like syntactic analysis, type checking, and lints should
752
+ happen before the program is executed regardless of when it is executed.
753
+
744
754
The compilation model centers on artifacts called _ crates_ . Each compilation
745
755
processes a single crate in source form, and if successful, produces a single
746
- crate in binary form: either an executable or a library.[ ^ cratesourcefile ]
756
+ crate in binary form: either an executable or some sort of
757
+ library.[ ^ cratesourcefile ]
747
758
748
759
[ ^ cratesourcefile ] : A crate is somewhat analogous to an * assembly* in the
749
760
ECMA-335 CLI model, a * library* in the SML/NJ Compilation Manager, a * unit*
@@ -764,21 +775,25 @@ extension `.rs`.
764
775
A Rust source file describes a module, the name and location of which &mdash ;
765
776
in the module tree of the current crate &mdash ; are defined from outside the
766
777
source file: either by an explicit ` mod_item ` in a referencing source file, or
767
- by the name of the crate itself.
778
+ by the name of the crate itself. Every source file is a module, but not every
779
+ module needs its own source file: [ module definitions] ( #modules ) can be nested
780
+ within one file.
768
781
769
782
Each source file contains a sequence of zero or more ` item ` definitions, and
770
- may optionally begin with any number of ` attributes ` that apply to the
771
- containing module. Attributes on the anonymous crate module define important
772
- metadata that influences the behavior of the compiler.
783
+ may optionally begin with any number of [ attributes] (#Items and attributes)
784
+ that apply to the containing module, most of which influence the behavior of
785
+ the compiler. The anonymous crate module can have additional attributes that
786
+ apply to the crate as a whole.
773
787
774
788
``` no_run
775
- // Crate name
789
+ // Specify the crate name.
776
790
#![crate_name = "projx"]
777
791
778
- // Specify the output type
792
+ // Specify the type of output artifact.
779
793
#![crate_type = "lib"]
780
794
781
- // Turn on a warning
795
+ // Turn on a warning.
796
+ // This can be done in any module, not just the anonymous crate module.
782
797
#![warn(non_camel_case_types)]
783
798
```
784
799
0 commit comments