10
10
>   ;  ;   ;  ; [ _ Expression_ ] ( ` , ` [ _ Expression_ ] )<sup >\* </sup > ` , ` <sup >?</sup >\
11
11
>   ;  ; | [ _ Expression_ ] ` ; ` [ _ Expression_ ]
12
12
13
- An _ [ array] ( ../types/array.md ) expression_ can be written by
14
- enclosing zero or more comma-separated expressions of uniform type in square
15
- brackets. This produces an array containing each of these values in the
16
- order they are written.
13
+ An _ [ array] expression_ can be written by enclosing zero or more
14
+ comma-separated expressions of uniform type in square brackets. This produces
15
+ an array containing each of these values in the order they are written.
17
16
18
17
Alternatively there can be exactly two expressions inside the brackets,
19
- separated by a semi-colon. The expression after the ` ; ` must have type
20
- ` usize ` and be a [ constant expression] ,
21
- such as a [ literal] ( ../tokens.md#literals ) or a [ constant
22
- item] ( ../items/constant-items.md ) . ` [a; b] ` creates an array containing ` b `
23
- copies of the value of ` a ` . If the expression after the semi-colon has a value
24
- greater than 1 then this requires that the type of ` a ` is
25
- [ ` Copy ` ] ( ../special-types-and-traits.md#copy ) .
18
+ separated by a semicolon. The expression after the ` ; ` must have type ` usize `
19
+ and be a [ constant expression] , such as a [ literal] or a [ constant item] . `[ a;
20
+ b] ` creates an array containing ` b` copies of the value of ` a`. If the
21
+ expression after the semicolon has a value greater than 1 then this requires
22
+ that the type of ` a ` is [ ` Copy ` ] .
26
23
27
24
``` rust
28
25
[1 , 2 , 3 , 4 ];
@@ -44,10 +41,9 @@ expressions].
44
41
> _ IndexExpression_ :\
45
42
>   ;  ; [ _ Expression_ ] ` [ ` [ _ Expression_ ] ` ] `
46
43
47
- [ Array] ( ../types/array.md ) and [ slice] ( ../types/slice.md ) -typed expressions can be
48
- indexed by writing a square-bracket-enclosed expression of type ` usize ` (the
49
- index) after them. When the array is mutable, the resulting [ memory location]
50
- can be assigned to.
44
+ [ Array] and [ slice] -typed expressions can be indexed by writing a
45
+ square-bracket-enclosed expression of type ` usize ` (the index) after them.
46
+ When the array is mutable, the resulting [ memory location] can be assigned to.
51
47
52
48
For other types an index expression ` a[b] ` is equivalent to
53
49
` *std::ops::Index::index(&a, b) ` , or
@@ -81,11 +77,16 @@ arr[10]; // warning: index out of bounds
81
77
The array index expression can be implemented for types other than arrays and slices
82
78
by implementing the [ Index] and [ IndexMut] traits.
83
79
80
+ [ `Copy` ] : ../special-types-and-traits.md#copy
84
81
[ IndexMut ] : ../../std/ops/trait.IndexMut.html
85
82
[ Index ] : ../../std/ops/trait.Index.html
86
83
[ Inner attributes ] : ../attributes.md
87
84
[ _Expression_ ] : ../expressions.md
88
85
[ _InnerAttribute_ ] : ../attributes.md
86
+ [ array ] : ../types/array.md
89
87
[ attributes on block expressions ] : block-expr.md#attributes-on-block-expressions
90
88
[ constant expression ] : ../const_eval.md#constant-expressions
89
+ [ constant item ] : ../items/constant-items.md
90
+ [ literal ] : ../tokens.md#literals
91
91
[ memory location ] : ../expressions.md#place-expressions-and-value-expressions
92
+ [ slice ] : ../types/slice.md
0 commit comments