1010>   ;  ;   ;  ; [ _ Expression_ ] ( ` , ` [ _ Expression_ ] )<sup >\* </sup > ` , ` <sup >?</sup >\
1111>   ;  ; | [ _ Expression_ ] ` ; ` [ _ Expression_ ]
1212
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.
1716
1817Alternatively 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 ` ] .
2623
2724``` rust
2825[1 , 2 , 3 , 4 ];
@@ -44,10 +41,9 @@ expressions].
4441> _ IndexExpression_ :\
4542>   ;  ; [ _ Expression_ ] ` [ ` [ _ Expression_ ] ` ] `
4643
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.
5147
5248For other types an index expression ` a[b] ` is equivalent to
5349` *std::ops::Index::index(&a, b) ` , or
@@ -81,11 +77,16 @@ arr[10]; // warning: index out of bounds
8177The array index expression can be implemented for types other than arrays and slices
8278by implementing the [ Index] and [ IndexMut] traits.
8379
80+ [ `Copy` ] : ../special-types-and-traits.md#copy
8481[ IndexMut ] : ../../std/ops/trait.IndexMut.html
8582[ Index ] : ../../std/ops/trait.Index.html
8683[ Inner attributes ] : ../attributes.md
8784[ _Expression_ ] : ../expressions.md
8885[ _InnerAttribute_ ] : ../attributes.md
86+ [ array ] : ../types/array.md
8987[ attributes on block expressions ] : block-expr.md#attributes-on-block-expressions
9088[ constant expression ] : ../const_eval.md#constant-expressions
89+ [ constant item ] : ../items/constant-items.md
90+ [ literal ] : ../tokens.md#literals
9191[ memory location ] : ../expressions.md#place-expressions-and-value-expressions
92+ [ slice ] : ../types/slice.md
0 commit comments