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/doc/rust.md
+44-25Lines changed: 44 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -116,8 +116,12 @@ production. See [tokens](#tokens) for more information.
116
116
Rust input is interpreted as a sequence of Unicode codepoints encoded in UTF-8,
117
117
normalized to Unicode normalization form NFKC.
118
118
Most Rust grammar rules are defined in terms of printable ASCII-range codepoints,
119
-
but a small number are defined in terms of Unicode properties or explicit codepoint lists.
120
-
^[Substitute definitions for the special Unicode productions are provided to the grammar verifier, restricted to ASCII range, when verifying the grammar in this document.]
119
+
but a small number are defined in terms of Unicode properties or explicit
120
+
codepoint lists. [^inputformat]
121
+
122
+
[^inputformat]: Substitute definitions for the special Unicode productions are
123
+
provided to the grammar verifier, restricted to ASCII range, when verifying
124
+
the grammar in this document.
121
125
122
126
## Special Unicode Productions
123
127
@@ -631,10 +635,13 @@ Semantic rules called "dynamic semantics" govern the behavior of programs at run
631
635
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.
632
636
633
637
The compilation model centres on artifacts called _crates_.
634
-
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.^[A crate is somewhat
635
-
analogous to an *assembly* in the ECMA-335 CLI model, a *library* in the
636
-
SML/NJ Compilation Manager, a *unit* in the Owens and Flatt module system,
637
-
or a *configuration* in Mesa.]
638
+
Each compilation processes a single crate in source form, and if successful,
639
+
produces a single crate in binary form: either an executable or a
640
+
library.[^cratesourcefile]
641
+
642
+
[^cratesourcefile]: A crate is somewhat analogous to an *assembly* in the
643
+
ECMA-335 CLI model, a *library* in the SML/NJ Compilation Manager, a *unit*
644
+
in the Owens and Flatt module system, or a *configuration* in Mesa.
638
645
639
646
A _crate_ is a unit of compilation and linking, as well as versioning, distribution and runtime loading.
640
647
A crate contains a _tree_ of nested [module](#modules) scopes.
@@ -3246,12 +3253,17 @@ types. User-defined types have limited capabilities.
3246
3253
3247
3254
The primitive types are the following:
3248
3255
3249
-
* The "unit" type `()`, having the single "unit" value `()` (occasionally called "nil").
3250
-
^[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.]
3256
+
* The "unit" type `()`, having the single "unit" value `()` (occasionally called
3257
+
"nil"). [^unittype]
3251
3258
* The boolean type `bool` with values `true` and `false`.
3252
3259
* The machine types.
3253
3260
* The machine-dependent integer and floating-point types.
3254
3261
3262
+
[^unittype]: The "unit" value `()` is *not* a sentinel "null pointer" value for
3263
+
reference slots; the "unit" type is the implicit return type from functions
3264
+
otherwise lacking a return type, and can be used in other contexts (such as
3265
+
message-sending or type-parametric code) as a zero-size type.]
3266
+
3255
3267
#### Machine types
3256
3268
3257
3269
The machine types are the following:
@@ -3270,16 +3282,19 @@ The machine types are the following:
3270
3282
3271
3283
#### Machine-dependent integer types
3272
3284
3273
-
The Rust type `uint`^[A Rust `uint` is analogous to a C99 `uintptr_t`.] is an
3285
+
The Rust type `uint`[^rustuint] is an
3274
3286
unsigned integer type with target-machine-dependent size. Its size, in
3275
3287
bits, is equal to the number of bits required to hold any memory address on
3276
3288
the target machine.
3277
3289
3278
-
The Rust type `int`^[A Rust `int` is analogous to a C99 `intptr_t`.] is a
3290
+
The Rust type `int`[^rustint] is a
3279
3291
two's complement signed integer type with target-machine-dependent size. Its
3280
3292
size, in bits, is equal to the size of the rust type `uint` on the same target
3281
3293
machine.
3282
3294
3295
+
[^rustuint]: A Rust `uint` is analogous to a C99 `uintptr_t`.
3296
+
[^rustint]: A Rust `int` is analogous to a C99 `intptr_t`.
3297
+
3283
3298
### Textual types
3284
3299
3285
3300
The types `char` and `str` hold textual data.
@@ -3352,10 +3367,12 @@ and access to a vector is always bounds-checked.
3352
3367
3353
3368
### Structure types
3354
3369
3355
-
A `struct`*type* is a heterogeneous product of other types, called the *fields* of the type.
3356
-
^[`struct` types are analogous `struct` types in C,
3357
-
the *record* types of the ML family,
3358
-
or the *structure* types of the Lisp family.]
3370
+
A `struct`*type* is a heterogeneous product of other types, called the *fields*
3371
+
of the type.[^structtype]
3372
+
3373
+
[^structtype]: `struct` types are analogous `struct` types in C,
3374
+
the *record* types of the ML family,
3375
+
or the *structure* types of the Lisp family.
3359
3376
3360
3377
New instances of a `struct` can be constructed with a [struct expression](#structure-expressions).
3361
3378
@@ -3375,9 +3392,10 @@ is the only value that inhabits such a type.
3375
3392
### Enumerated types
3376
3393
3377
3394
An *enumerated type* is a nominal, heterogeneous disjoint union type,
3378
-
denoted by the name of an [`enum` item](#enumerations).
3379
-
^[The `enum` type is analogous to a `data` constructor declaration in ML,
3380
-
or a *pick ADT* in Limbo.]
3395
+
denoted by the name of an [`enum` item](#enumerations). [^enumtype]
3396
+
3397
+
[^enumtype]: The `enum` type is analogous to a `data` constructor declaration in
3398
+
ML, or a *pick ADT* in Limbo.
3381
3399
3382
3400
An [`enum` item](#enumerations) declares both the type and a number of *variant constructors*,
3383
3401
each of which is independently named and takes an optional tuple of arguments.
@@ -3804,14 +3822,15 @@ By default, the scheduler chooses the number of threads based on
3804
3822
the number of concurrent physical CPUs detected at startup.
3805
3823
It's also possible to override this choice at runtime.
3806
3824
When the number of tasks exceeds the number of threads — which is likely —
3807
-
the scheduler multiplexes the tasks onto threads.^[
3808
-
This is an M:N scheduler,
3809
-
which is known to give suboptimal results for CPU-bound concurrency problems.
3810
-
In such cases, running with the same number of threads and tasks can yield better results.
3811
-
Rust has M:N scheduling in order to support very large numbers of tasks
3812
-
in contexts where threads are too resource-intensive to use in large number.
3813
-
The cost of threads varies substantially per operating system, and is sometimes quite low,
3814
-
so this flexibility is not always worth exploiting.]
3825
+
the scheduler multiplexes the tasks onto threads.[^mnscheduler]
3826
+
3827
+
[^mnscheduler]: This is an M:N scheduler, which is known to give suboptimal
3828
+
results for CPU-bound concurrency problems. In such cases, running with the
3829
+
same number of threads and tasks can yield better results. Rust has M:N
3830
+
scheduling in order to support very large numbers of tasks in contexts where
3831
+
threads are too resource-intensive to use in large number. The cost of
3832
+
threads varies substantially per operating system, and is sometimes quite
3833
+
low, so this flexibility is not always worth exploiting.
0 commit comments