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: doc/rust.md
+26-40Lines changed: 26 additions & 40 deletions
Original file line number
Diff line number
Diff line change
@@ -388,11 +388,10 @@ Examples of floating-point literals of various forms:
388
388
12E+99_f64; // type f64
389
389
~~~~
390
390
391
-
##### Nil and boolean literals
391
+
##### Unit and boolean literals
392
392
393
-
The _nil value_, the only value of the type by the same name, is
394
-
written as `()`. The two values of the boolean type are written `true`
395
-
and `false`.
393
+
The _unit value_, the only value of the type that has the same name, is written as `()`.
394
+
The two values of the boolean type are written `true` and `false`.
396
395
397
396
### Symbols
398
397
@@ -564,23 +563,19 @@ This requirement most often affects name-designator pairs when they occur at the
564
563
565
564
# Crates and source files
566
565
567
-
Rust is a *compiled* language. Its semantics are divided along a
568
-
*phase distinction* between compile-time and run-time. Those semantic
569
-
rules that have a *static interpretation* govern the success or failure
570
-
of compilation. A program that fails to compile due to violation of a
571
-
compile-time rule has no defined semanticsat run-time; the compiler should
572
-
halt with an error report, and produce no executable artifact.
566
+
Rust is a *compiled* language.
567
+
Its semantics obey a *phase distinction* between compile-time and run-time.
568
+
Those semantic rules that have a *static interpretation* govern the success or failure of compilation.
569
+
We refer to these rules as "static semantics".
570
+
Semantic rules called "dynamic semantics" govern the behavior of programs at run-time.
571
+
A program that fails to compile due to violation of a compile-time rule has no defined dynamic semantics; the compiler should halt with an error report, and produce no executable artifact.
573
572
574
-
The compilation model centres on artifacts called _crates_. Each compilation
575
-
is directed towards a single crate in source form, and if successful,
576
-
produces a single crate in binary form: either an executable or a library.
573
+
The compilation model centres on artifacts called _crates_.
574
+
Each compilation processes a single crate in source form, and if successful, produces a single crate in binary form: either an executable or a library.
577
575
578
-
A _crate_ is a unit of compilation and linking, as well as versioning,
579
-
distribution and runtime loading. A crate contains a _tree_ of nested
580
-
[module](#modules) scopes. The top level of this tree is a module that is
581
-
anonymous -- from the point of view of paths within the module -- and any item
582
-
within a crate has a canonical [module path](#paths) denoting its location
583
-
within the crate's module tree.
576
+
A _crate_ is a unit of compilation and linking, as well as versioning, distribution and runtime loading.
577
+
A crate contains a _tree_ of nested [module](#modules) scopes.
578
+
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](#paths) denoting its location within the crate's module tree.
584
579
585
580
Crates are provided to the Rust compiler through two kinds of file:
586
581
@@ -590,18 +585,15 @@ Crates are provided to the Rust compiler through two kinds of file:
590
585
> **Note:** The functionality of crate files will be merged into source files in future versions of Rust.
591
586
> The separate processing of crate files, both their grammar and file extension, will be removed.
592
587
593
-
The Rust compiler is always invoked with a single input file, and always
594
-
produces a single output crate.
588
+
The Rust compiler is always invoked with a single crate file as input, and always produces a single output crate.
595
589
596
590
When the Rust compiler is invoked with a crate file, it reads the _explicit_
597
591
definition of the crate it's compiling from that file, and populates the
598
592
crate with modules derived from all the source files referenced by the
599
593
crate, reading and processing all the referenced modules at once.
600
594
601
-
When the Rust compiler is invoked with a source file, it creates an
602
-
_implicit_ crate and treats the source file as though it was referenced as
603
-
the sole module populating this implicit crate. The module name is derived
604
-
from the source file name, with the `.rs` extension removed.
595
+
When the Rust compiler is invoked with a source file, it creates an _implicit_ crate and treats the source file as if it is the sole module populating this explicit crate.
596
+
The module name is derived from the source file name, with the `.rs` extension removed.
605
597
606
598
## Crate files
607
599
@@ -658,10 +650,8 @@ containing source files and/or further subdirectories. The filesystem
658
650
directory associated with a `dir_directive` module can either be explicit,
659
651
or if omitted, is implicitly the same name as the module.
660
652
661
-
A `source_directive` references a source file, either explicitly or
662
-
implicitly by combining the module name with the file extension `.rs`. The
663
-
module contained in that source file is bound to the module path formed by
664
-
the `dir_directive` modules containing the `source_directive`.
653
+
A `source_directive` references a source file, either explicitly or implicitly, by combining the module name with the file extension `.rs`.
654
+
The module contained in that source file is bound to the module path formed by the `dir_directive` modules containing the `source_directive`.
665
655
666
656
## Source files
667
657
@@ -671,9 +661,8 @@ location of which -- in the module tree of the current crate -- is defined
671
661
from outside the source file: either by an explicit `source_directive` in
672
662
a referencing crate file, or by the filename of the source file itself.
673
663
674
-
A source file that contains a `main` function can be compiled to an
675
-
executable. If a `main` function is present,
676
-
its return type must be [`nil`](#primitive-types) and it must take no arguments.
664
+
A source file that contains a `main` function can be compiled to an executable.
665
+
If a `main` function is present, its return type must be [`unit`](#primitive-types) and it must take no arguments.
677
666
678
667
# Items and attributes
679
668
@@ -1494,10 +1483,10 @@ A temporary's lifetime equals the largest lifetime of any borrowed pointer that
1494
1483
1495
1484
A _literal expression_ consists of one of the [literal](#literals)
1496
1485
forms described earlier. It directly describes a number, character,
1497
-
string, boolean value, or the nil value.
1486
+
string, boolean value, or the unit value.
1498
1487
1499
1488
~~~~~~~~{.literals}
1500
-
(); // nil type
1489
+
(); // unit type
1501
1490
"hello"; // string type
1502
1491
'5'; // character type
1503
1492
5; // integer type
@@ -1862,7 +1851,7 @@ operators may be composed with the `=` operator. The expression `lval
1862
1851
OP= val` is equivalent to `lval = lval OP val`. For example, `x = x +
1863
1852
1` may be written as `x += 1`.
1864
1853
1865
-
Any such expression always has the [`nil`](#primitive-types) type.
1854
+
Any such expression always has the [`unit`](#primitive-types) type.
1866
1855
1867
1856
#### Operator precedence
1868
1857
@@ -2414,11 +2403,8 @@ types. User-defined types have limited capabilities.
2414
2403
2415
2404
The primitive types are the following:
2416
2405
2417
-
* The "nil" type `()`, having the single "nil" value `()`.^[The "nil" value
2418
-
`()` is *not* a sentinel "null pointer" value for reference slots; the "nil"
2419
-
type is the implicit return type from functions otherwise lacking a return
2420
-
type, and can be used in other contexts (such as message-sending or
2421
-
type-parametric code) as a zero-size type.]
2406
+
* The "unit" type `()`, having the single "unit" value `()` (occasionally called "nil").
2407
+
^[The "unit" value `()` is *not* a sentinel "null pointer" value for reference slots; the "unit" type is the implicit return type from functions otherwise lacking a return type, and can be used in other contexts (such as message-sending or type-parametric code) as a zero-size type.]
2422
2408
* The boolean type `bool` with values `true` and `false`.
2423
2409
* The machine types.
2424
2410
* The machine-dependent integer and floating-point types.
0 commit comments