Skip to content

Commit 695efb5

Browse files
committed
Rollup merge of #24548 - graydon:reference-tidying, r=steveklabnik
This just deletes some egregious lies and obsolete terminology -- all of which I originally wrote -- from the reference. I expect the reference itself will be deleted soon enough, but I found myself gritting teeth over these bits too much to let them into a 1.0 release.
2 parents cb7a127 + a99a8b0 commit 695efb5

File tree

3 files changed

+53
-96
lines changed

3 files changed

+53
-96
lines changed

src/doc/complement-lang-faq.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Yes. Calling C code from Rust is simple and exactly as efficient as calling C co
124124

125125
Yes. The Rust code has to be exposed via an `extern` declaration, which makes it C-ABI compatible. Such a function can be passed to C code as a function pointer or, if given the `#[no_mangle]` attribute to disable symbol mangling, can be called directly from C code.
126126

127-
## Why aren't function signatures inferred? Why only local slots?
127+
## Why aren't function signatures inferred? Why only local variables?
128128

129129
* Mechanically, it simplifies the inference algorithm; inference only requires looking at one function at a time.
130130
* The same simplification goes double for human readers. A reader does not need an IDE running an inference algorithm across an entire crate to be able to guess at a function's argument types; it's always explicit and nearby.

src/doc/grammar.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
This document is the primary reference for the Rust programming language grammar. It
66
provides only one kind of material:
77

8-
- Chapters that formally define the language grammar and, for each
9-
construct.
8+
- Chapters that formally define the language grammar.
109

1110
This document does not serve as an introduction to the language. Background
1211
familiarity with the language is assumed. A separate [guide] is available to
@@ -427,7 +426,7 @@ meta_seq : meta_item [ ',' meta_seq ] ? ;
427426
**FIXME:** grammar?
428427

429428
A _declaration statement_ is one that introduces one or more *names* into the
430-
enclosing statement block. The declared names may denote new slots or new
429+
enclosing statement block. The declared names may denote new variables or new
431430
items.
432431

433432
#### Item declarations
@@ -441,7 +440,7 @@ function, enumeration, structure, type, static, trait, implementation or module
441440
scope to a narrow region containing all of its uses; it is otherwise identical
442441
in meaning to declaring the item outside the statement block.
443442

444-
#### Slot declarations
443+
#### Variable declarations
445444

446445
```antlr
447446
let_decl : "let" pat [':' type ] ? [ init ] ? ';' ;
@@ -763,7 +762,7 @@ bound := path | lifetime
763762

764763
### Memory ownership
765764

766-
### Memory slots
765+
### Variables
767766

768767
### Boxes
769768

src/doc/reference.md

+48-90
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ type_path_tail : '<' type_expr [ ',' type_expr ] + '>'
564564

565565
A _path_ is a sequence of one or more path components _logically_ separated by
566566
a namespace qualifier (`::`). If a path consists of only one component, it may
567-
refer to either an [item](#items) or a [slot](#memory-slots) in a local control
567+
refer to either an [item](#items) or a [variable](#variables) in a local control
568568
scope. If a path has multiple components, it refers to an item.
569569

570570
Every item has a _canonical path_ within its crate, but the path naming an item
@@ -735,13 +735,11 @@ Rust syntax is restricted in two ways:
735735

736736
# Crates and source files
737737

738-
Rust is a *compiled* language. Its semantics obey a *phase distinction*
739-
between compile-time and run-time. Those semantic rules that have a *static
740-
interpretation* govern the success or failure of compilation. We refer to
741-
these rules as "static semantics". Semantic rules called "dynamic semantics"
742-
govern the behavior of programs at run-time. A program that fails to compile
743-
due to violation of a compile-time rule has no defined dynamic semantics; the
744-
compiler should halt with an error report, and produce no executable artifact.
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
740+
interpretation* govern the success or failure of compilation. Those semantics
741+
that have a *dynamic interpretation* govern the behavior of the program at
742+
run-time.
745743

746744
The compilation model centers on artifacts called _crates_. Each compilation
747745
processes a single crate in source form, and if successful, produces a single
@@ -1064,9 +1062,9 @@ fn main() {}
10641062
A _function item_ defines a sequence of [statements](#statements) and an
10651063
optional final [expression](#expressions), along with a name and a set of
10661064
parameters. Functions are declared with the keyword `fn`. Functions declare a
1067-
set of *input* [*slots*](#memory-slots) as parameters, through which the caller
1068-
passes arguments into the function, and an *output* [*slot*](#memory-slots)
1069-
through which the function passes results back to the caller.
1065+
set of *input* [*variables*](#variables) as parameters, through which the caller
1066+
passes arguments into the function, and the *output* [*type*](#types)
1067+
of the value the function will return to its caller on completion.
10701068

10711069
A function may also be copied into a first-class *value*, in which case the
10721070
value has the corresponding [*function type*](#function-types), and can be used
@@ -1229,7 +1227,7 @@ be undesired.
12291227
#### Diverging functions
12301228

12311229
A special kind of function can be declared with a `!` character where the
1232-
output slot type would normally be. For example:
1230+
output type would normally be. For example:
12331231

12341232
```
12351233
fn my_err(s: &str) -> ! {
@@ -1302,18 +1300,11 @@ contiguous stack segments like C.
13021300

13031301
A _type alias_ defines a new name for an existing [type](#types). Type
13041302
aliases are declared with the keyword `type`. Every value has a single,
1305-
specific type; the type-specified aspects of a value include:
1303+
specific type, but may implement several different traits, or be compatible with
1304+
several different type constraints.
13061305

1307-
* Whether the value is composed of sub-values or is indivisible.
1308-
* Whether the value represents textual or numerical information.
1309-
* Whether the value represents integral or floating-point information.
1310-
* The sequence of memory operations required to access the value.
1311-
* The [kind](#type-kinds) of the type.
1312-
1313-
For example, the type `(u8, u8)` defines the set of immutable values that are
1314-
composite pairs, each containing two unsigned 8-bit integers accessed by
1315-
pattern-matching and laid out in memory with the `x` component preceding the
1316-
`y` component:
1306+
For example, the following defines the type `Point` as a synonym for the type
1307+
`(u8, u8)`, the type of pairs of unsigned 8 bit integers.:
13171308

13181309
```
13191310
type Point = (u8, u8);
@@ -2551,7 +2542,7 @@ statements](#expression-statements).
25512542
### Declaration statements
25522543

25532544
A _declaration statement_ is one that introduces one or more *names* into the
2554-
enclosing statement block. The declared names may denote new slots or new
2545+
enclosing statement block. The declared names may denote new variables or new
25552546
items.
25562547

25572548
#### Item declarations
@@ -2566,18 +2557,18 @@ in meaning to declaring the item outside the statement block.
25662557
> **Note**: there is no implicit capture of the function's dynamic environment when
25672558
> declaring a function-local item.
25682559
2569-
#### Slot declarations
2560+
#### Variable declarations
25702561

25712562
```{.ebnf .gram}
25722563
let_decl : "let" pat [':' type ] ? [ init ] ? ';' ;
25732564
init : [ '=' ] expr ;
25742565
```
25752566

2576-
A _slot declaration_ introduces a new set of slots, given by a pattern. The
2567+
A _variable declaration_ introduces a new set of variable, given by a pattern. The
25772568
pattern may be followed by a type annotation, and/or an initializer expression.
25782569
When no type annotation is given, the compiler will infer the type, or signal
25792570
an error if insufficient type information is available for definite inference.
2580-
Any slots introduced by a slot declaration are visible from the point of
2571+
Any variables introduced by a variable declaration are visible from the point of
25812572
declaration until the end of the enclosing block scope.
25822573

25832574
### Expression statements
@@ -2632,7 +2623,7 @@ of any reference that points to it.
26322623

26332624
#### Moved and copied types
26342625

2635-
When a [local variable](#memory-slots) is used as an
2626+
When a [local variable](#variables) is used as an
26362627
[rvalue](#lvalues,-rvalues-and-temporaries) the variable will either be moved
26372628
or copied, depending on its type. All values whose type implements `Copy` are
26382629
copied, all others are moved.
@@ -3042,10 +3033,9 @@ paren_expr_list : '(' expr_list ')' ;
30423033
call_expr : expr paren_expr_list ;
30433034
```
30443035

3045-
A _call expression_ invokes a function, providing zero or more input slots and
3046-
an optional reference slot to serve as the function's output, bound to the
3047-
`lval` on the right hand side of the call. If the function eventually returns,
3048-
then the expression completes.
3036+
A _call expression_ invokes a function, providing zero or more input variables
3037+
and an optional location to move the function's output into. If the function
3038+
eventually returns, then the expression completes.
30493039

30503040
Some examples of call expressions:
30513041

@@ -3456,9 +3446,9 @@ return_expr : "return" expr ? ;
34563446
```
34573447

34583448
Return expressions are denoted with the keyword `return`. Evaluating a `return`
3459-
expression moves its argument into the output slot of the current function,
3460-
destroys the current function activation frame, and transfers control to the
3461-
caller frame.
3449+
expression moves its argument into the designated output location for the
3450+
current function call, destroys the current function activation frame, and
3451+
transfers control to the caller frame.
34623452

34633453
An example of a `return` expression:
34643454

@@ -3475,7 +3465,7 @@ fn max(a: i32, b: i32) -> i32 {
34753465

34763466
## Types
34773467

3478-
Every slot, item and value in a Rust program has a type. The _type_ of a
3468+
Every variable, item and value in a Rust program has a type. The _type_ of a
34793469
*value* defines the interpretation of the memory holding it.
34803470

34813471
Built-in types and type-constructors are tightly integrated into the language,
@@ -3493,7 +3483,7 @@ The primitive types are the following:
34933483
* The machine-dependent integer and floating-point types.
34943484

34953485
[^unittype]: The "unit" value `()` is *not* a sentinel "null pointer" value for
3496-
reference slots; the "unit" type is the implicit return type from functions
3486+
reference variables; the "unit" type is the implicit return type from functions
34973487
otherwise lacking a return type, and can be used in other contexts (such as
34983488
message-sending or type-parametric code) as a zero-size type.]
34993489

@@ -3831,29 +3821,33 @@ impl Printable for String {
38313821
`self` refers to the value of type `String` that is the receiver for a call to
38323822
the method `make_string`.
38333823

3834-
# The `Copy` trait
3824+
# Special traits
3825+
3826+
Several traits define special evaluation behavior.
38353827

3836-
Rust has a special trait, `Copy`, which when implemented changes the semantics
3837-
of a value. Values whose type implements `Copy` are copied rather than moved
3838-
upon assignment.
3828+
## The `Copy` trait
38393829

3840-
# The `Sized` trait
3830+
The `Copy` trait changes the semantics of a type implementing it. Values whose
3831+
type implements `Copy` are copied rather than moved upon assignment.
38413832

3842-
`Sized` is a special trait which indicates that the size of this type is known
3843-
at compile-time.
3833+
## The `Sized` trait
38443834

3845-
# The `Drop` trait
3835+
The `Sized` trait indicates that the size of this type is known at compile-time.
3836+
3837+
## The `Drop` trait
38463838

38473839
The `Drop` trait provides a destructor, to be run whenever a value of this type
38483840
is to be destroyed.
38493841

38503842
# Memory model
38513843

38523844
A Rust program's memory consists of a static set of *items* and a *heap*.
3853-
Immutable portions of the heap may be shared between threads, mutable portions
3854-
may not.
3845+
Immutable portions of the heap may be safely shared between threads, mutable
3846+
portions may not be safely shared, but several mechanisms for effectively-safe
3847+
sharing of mutable values, built on unsafe code but enforcing a safe locking
3848+
discipline, exist in the standard library.
38553849

3856-
Allocations in the stack consist of *slots*, and allocations in the heap
3850+
Allocations in the stack consist of *variables*, and allocations in the heap
38573851
consist of *boxes*.
38583852

38593853
### Memory allocation and lifetime
@@ -3872,10 +3866,11 @@ in the heap, heap allocations may outlive the frame they are allocated within.
38723866
When a stack frame is exited, its local allocations are all released, and its
38733867
references to boxes are dropped.
38743868

3875-
### Memory slots
3869+
### Variables
38763870

3877-
A _slot_ is a component of a stack frame, either a function parameter, a
3878-
[temporary](#lvalues,-rvalues-and-temporaries), or a local variable.
3871+
A _variable_ is a component of a stack frame, either a named function parameter,
3872+
an anonymous [temporary](#lvalues,-rvalues-and-temporaries), or a named local
3873+
variable.
38793874

38803875
A _local variable_ (or *stack-local* allocation) holds a value directly,
38813876
allocated within the stack's memory. The value is a part of the stack frame.
@@ -3888,7 +3883,7 @@ Box<i32>, y: Box<i32>)` declare one mutable variable `x` and one immutable
38883883
variable `y`).
38893884

38903885
Methods that take either `self` or `Box<Self>` can optionally place them in a
3891-
mutable slot by prefixing them with `mut` (similar to regular arguments):
3886+
mutable variable by prefixing them with `mut` (similar to regular arguments):
38923887

38933888
```
38943889
trait Changer {
@@ -3903,44 +3898,7 @@ state. Subsequent statements within a function may or may not initialize the
39033898
local variables. Local variables can be used only after they have been
39043899
initialized; this is enforced by the compiler.
39053900

3906-
# Runtime services, linkage and debugging
3907-
3908-
The Rust _runtime_ is a relatively compact collection of Rust code that
3909-
provides fundamental services and datatypes to all Rust threads at run-time. It
3910-
is smaller and simpler than many modern language runtimes. It is tightly
3911-
integrated into the language's execution model of memory, threads, communication
3912-
and logging.
3913-
3914-
### Memory allocation
3915-
3916-
The runtime memory-management system is based on a _service-provider
3917-
interface_, through which the runtime requests blocks of memory from its
3918-
environment and releases them back to its environment when they are no longer
3919-
needed. The default implementation of the service-provider interface consists
3920-
of the C runtime functions `malloc` and `free`.
3921-
3922-
The runtime memory-management system, in turn, supplies Rust threads with
3923-
facilities for allocating releasing stacks, as well as allocating and freeing
3924-
heap data.
3925-
3926-
### Built in types
3927-
3928-
The runtime provides C and Rust code to assist with various built-in types,
3929-
such as arrays, strings, and the low level communication system (ports,
3930-
channels, threads).
3931-
3932-
Support for other built-in types such as simple types, tuples and enums is
3933-
open-coded by the Rust compiler.
3934-
3935-
### Thread scheduling and communication
3936-
3937-
The runtime provides code to manage inter-thread communication. This includes
3938-
the system of thread-lifecycle state transitions depending on the contents of
3939-
queues, as well as code to copy values between queues and their recipients and
3940-
to serialize values for transmission over operating-system inter-process
3941-
communication facilities.
3942-
3943-
### Linkage
3901+
# Linkage
39443902

39453903
The Rust compiler supports various methods to link crates together both
39463904
statically and dynamically. This section will explore the various methods to

0 commit comments

Comments
 (0)