@@ -564,7 +564,7 @@ type_path_tail : '<' type_expr [ ',' type_expr ] + '>'
564
564
565
565
A _ path_ is a sequence of one or more path components _ logically_ separated by
566
566
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
568
568
scope. If a path has multiple components, it refers to an item.
569
569
570
570
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:
735
735
736
736
# Crates and source files
737
737
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.
745
743
746
744
The compilation model centers on artifacts called _ crates_ . Each compilation
747
745
processes a single crate in source form, and if successful, produces a single
@@ -1064,9 +1062,9 @@ fn main() {}
1064
1062
A _ function item_ defines a sequence of [ statements] ( #statements ) and an
1065
1063
optional final [ expression] ( #expressions ) , along with a name and a set of
1066
1064
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 .
1070
1068
1071
1069
A function may also be copied into a first-class * value* , in which case the
1072
1070
value has the corresponding [ * function type* ] ( #function-types ) , and can be used
@@ -1229,7 +1227,7 @@ be undesired.
1229
1227
#### Diverging functions
1230
1228
1231
1229
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:
1233
1231
1234
1232
```
1235
1233
fn my_err(s: &str) -> ! {
@@ -1302,18 +1300,11 @@ contiguous stack segments like C.
1302
1300
1303
1301
A _ type alias_ defines a new name for an existing [ type] ( #types ) . Type
1304
1302
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.
1306
1305
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.:
1317
1308
1318
1309
```
1319
1310
type Point = (u8, u8);
@@ -2551,7 +2542,7 @@ statements](#expression-statements).
2551
2542
### Declaration statements
2552
2543
2553
2544
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
2555
2546
items.
2556
2547
2557
2548
#### Item declarations
@@ -2566,18 +2557,18 @@ in meaning to declaring the item outside the statement block.
2566
2557
> ** Note** : there is no implicit capture of the function's dynamic environment when
2567
2558
> declaring a function-local item.
2568
2559
2569
- #### Slot declarations
2560
+ #### Variable declarations
2570
2561
2571
2562
``` {.ebnf .gram}
2572
2563
let_decl : "let" pat [':' type ] ? [ init ] ? ';' ;
2573
2564
init : [ '=' ] expr ;
2574
2565
```
2575
2566
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
2577
2568
pattern may be followed by a type annotation, and/or an initializer expression.
2578
2569
When no type annotation is given, the compiler will infer the type, or signal
2579
2570
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
2581
2572
declaration until the end of the enclosing block scope.
2582
2573
2583
2574
### Expression statements
@@ -2632,7 +2623,7 @@ of any reference that points to it.
2632
2623
2633
2624
#### Moved and copied types
2634
2625
2635
- When a [ local variable] ( #memory-slots ) is used as an
2626
+ When a [ local variable] ( #variables ) is used as an
2636
2627
[ rvalue] ( #lvalues,-rvalues-and-temporaries ) the variable will either be moved
2637
2628
or copied, depending on its type. All values whose type implements ` Copy ` are
2638
2629
copied, all others are moved.
@@ -3042,10 +3033,9 @@ paren_expr_list : '(' expr_list ')' ;
3042
3033
call_expr : expr paren_expr_list ;
3043
3034
```
3044
3035
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.
3049
3039
3050
3040
Some examples of call expressions:
3051
3041
@@ -3456,9 +3446,9 @@ return_expr : "return" expr ? ;
3456
3446
```
3457
3447
3458
3448
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.
3462
3452
3463
3453
An example of a ` return ` expression:
3464
3454
@@ -3475,7 +3465,7 @@ fn max(a: i32, b: i32) -> i32 {
3475
3465
3476
3466
## Types
3477
3467
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
3479
3469
* value* defines the interpretation of the memory holding it.
3480
3470
3481
3471
Built-in types and type-constructors are tightly integrated into the language,
@@ -3493,7 +3483,7 @@ The primitive types are the following:
3493
3483
* The machine-dependent integer and floating-point types.
3494
3484
3495
3485
[ ^ 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
3497
3487
otherwise lacking a return type, and can be used in other contexts (such as
3498
3488
message-sending or type-parametric code) as a zero-size type.]
3499
3489
@@ -3831,29 +3821,33 @@ impl Printable for String {
3831
3821
` self ` refers to the value of type ` String ` that is the receiver for a call to
3832
3822
the method ` make_string ` .
3833
3823
3834
- # The ` Copy ` trait
3824
+ # Special traits
3825
+
3826
+ Several traits define special evaluation behavior.
3835
3827
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
3839
3829
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.
3841
3832
3842
- ` Sized ` is a special trait which indicates that the size of this type is known
3843
- at compile-time.
3833
+ ## The ` Sized ` trait
3844
3834
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
3846
3838
3847
3839
The ` Drop ` trait provides a destructor, to be run whenever a value of this type
3848
3840
is to be destroyed.
3849
3841
3850
3842
# Memory model
3851
3843
3852
3844
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.
3855
3849
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
3857
3851
consist of * boxes* .
3858
3852
3859
3853
### Memory allocation and lifetime
@@ -3872,10 +3866,11 @@ in the heap, heap allocations may outlive the frame they are allocated within.
3872
3866
When a stack frame is exited, its local allocations are all released, and its
3873
3867
references to boxes are dropped.
3874
3868
3875
- ### Memory slots
3869
+ ### Variables
3876
3870
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.
3879
3874
3880
3875
A _ local variable_ (or * stack-local* allocation) holds a value directly,
3881
3876
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
3888
3883
variable ` y ` ).
3889
3884
3890
3885
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):
3892
3887
3893
3888
```
3894
3889
trait Changer {
@@ -3903,44 +3898,7 @@ state. Subsequent statements within a function may or may not initialize the
3903
3898
local variables. Local variables can be used only after they have been
3904
3899
initialized; this is enforced by the compiler.
3905
3900
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
3944
3902
3945
3903
The Rust compiler supports various methods to link crates together both
3946
3904
statically and dynamically. This section will explore the various methods to
0 commit comments