Skip to content

Commit 8a41485

Browse files
committed
auto merge of #14680 : Kimundi/rust/master, r=brson
Also updated/corrected a few other details in the tuple and struct sections.
2 parents 61d7917 + 792fae3 commit 8a41485

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/doc/rust.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,10 +2524,10 @@ Note that for a given *unit-like* structure type, this will always be the same v
25242524

25252525
A structure expression can terminate with the syntax `..` followed by an expression to denote a functional update.
25262526
The expression following `..` (the base) must have the same structure type as the new structure type being formed.
2527-
The entire expression denotes the result of allocating a new structure
2527+
The entire expression denotes the result of constructing a new structure
25282528
(with the same type as the base expression)
25292529
with the given values for the fields that were explicitly specified
2530-
and the values in the base record for all other fields.
2530+
and the values in the base expression for all other fields.
25312531

25322532
~~~~
25332533
# struct Point3d { x: int, y: int, z: int }
@@ -2575,15 +2575,15 @@ when not immediately followed by a parenthesized expression-list (the latter is
25752575
A field expression denotes a field of a [structure](#structure-types).
25762576

25772577
~~~~ {.ignore .field}
2578-
myrecord.myfield;
2578+
mystruct.myfield;
25792579
foo().x;
25802580
(Struct {a: 10, b: 20}).a;
25812581
~~~~
25822582

2583-
A field access on a record is an [lvalue](#lvalues-rvalues-and-temporaries) referring to the value of that field.
2584-
When the field is mutable, it can be [assigned](#assignment-expressions) to.
2583+
A field access is an [lvalue](#lvalues-rvalues-and-temporaries) referring to the value of that field.
2584+
When the type providing the field inherits mutabilty, it can be [assigned](#assignment-expressions) to.
25852585

2586-
When the type of the expression to the left of the dot is a pointer to a record or structure,
2586+
Also, if the type of the expression to the left of the dot is a pointer,
25872587
it is automatically dereferenced to make the field access possible.
25882588

25892589
### Vector expressions
@@ -3038,7 +3038,7 @@ match_pat : pat [ '|' pat ] * [ "if" expr ] ? ;
30383038

30393039
A `match` expression branches on a *pattern*. The exact form of matching that
30403040
occurs depends on the pattern. Patterns consist of some combination of
3041-
literals, destructured vectors or enum constructors, structures, records and
3041+
literals, destructured vectors or enum constructors, structures and
30423042
tuples, variable binding specifications, wildcards (`..`), and placeholders
30433043
(`_`). A `match` expression has a *head expression*, which is the value to
30443044
compare to the patterns. The type of the patterns must equal the type of the
@@ -3315,17 +3315,16 @@ such as `&str` or `String`.
33153315

33163316
### Tuple types
33173317

3318-
The tuple type-constructor forms a new heterogeneous product of values similar
3319-
to the record type-constructor. The differences are as follows:
3320-
3321-
* tuple elements cannot be mutable, unlike record fields
3322-
* tuple elements are not named and can be accessed only by pattern-matching
3318+
A tuple *type* is a heterogeneous product of other types, called the *elements*
3319+
of the tuple. It has no nominal name and is instead structurally typed.
33233320

33243321
Tuple types and values are denoted by listing the types or values of their
33253322
elements, respectively, in a parenthesized, comma-separated
33263323
list.
33273324

3328-
The members of a tuple are laid out in memory contiguously, like a record, in
3325+
Because tuple elements don't have a name, they can only be accessed by pattern-matching.
3326+
3327+
The members of a tuple are laid out in memory contiguously, in
33293328
order specified by the tuple type.
33303329

33313330
An example of a tuple type and its use:
@@ -3377,12 +3376,13 @@ of the type.[^structtype]
33773376

33783377
New instances of a `struct` can be constructed with a [struct expression](#structure-expressions).
33793378

3380-
The memory order of fields in a `struct` is given by the item defining it.
3381-
Fields may be given in any order in a corresponding struct *expression*;
3382-
the resulting `struct` value will always be laid out in memory in the order specified by the corresponding *item*.
3379+
The memory layout of a `struct` is undefined by default to allow for compiler optimziations like
3380+
field reordering, but it can be fixed with the `#[repr(...)]` attribute.
3381+
In either case, fields may be given in any order in a corresponding struct *expression*;
3382+
the resulting `struct` value will always have the same memory layout.
33833383

33843384
The fields of a `struct` may be qualified by [visibility modifiers](#re-exporting-and-visibility),
3385-
to restrict access to implementation-private data in a structure.
3385+
to allow access to data in a structure outside a module.
33863386

33873387
A _tuple struct_ type is just like a structure type, except that the fields are anonymous.
33883388

@@ -3933,7 +3933,7 @@ The runtime provides C and Rust code to assist with various built-in types,
39333933
such as vectors, strings, and the low level communication system (ports,
39343934
channels, tasks).
39353935

3936-
Support for other built-in types such as simple types, tuples, records, and
3936+
Support for other built-in types such as simple types, tuples and
39373937
enums is open-coded by the Rust compiler.
39383938

39393939
### Task scheduling and communication

0 commit comments

Comments
 (0)