Skip to content

Commit f86e064

Browse files
authored
Merge pull request #1928 from theemathas/patch-1
Array expression repeat operands can be const blocks.
2 parents 9574a86 + 318b47c commit f86e064

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/expressions/array-expr.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ An array expression of this form creates an array with the length of the value o
5353
That is, `[a; b]` creates an array containing `b` copies of the value of `a`.
5454

5555
r[expr.array.repeat-copy]
56-
If the length operand has a value greater than 1 then this requires that the type of the repeat operand is [`Copy`] or that it must be a [path] to a constant item.
56+
If the length operand has a value greater than 1 then this requires the repeat operand to have a type that implements [`Copy`], to be a [const block expression], or to be a [path] to a constant item.
5757

5858
r[expr.array.repeat-const-item]
59-
When the repeat operand is a constant item, it is evaluated the length operand's value times.
59+
When the repeat operand is a const block or a path to a constant item, it is evaluated the number of times specified in the length operand.
6060

6161
r[expr.array.repeat-evaluation-zero]
62-
If that value is `0`, then the constant item is not evaluated at all.
62+
If that value is `0`, then the const block or constant item is not evaluated at all.
6363

6464
r[expr.array.repeat-non-const]
65-
For expressions that are not a constant item, it is evaluated exactly once, and then the result is copied the length operand's value times.
65+
For expressions that are neither a const block nor a path to a constant item, it is evaluated exactly once, and then the result is copied the length operand's value times.
6666

6767
```rust
6868
[1, 2, 3, 4];
@@ -123,6 +123,7 @@ The array index expression can be implemented for types other than arrays and sl
123123
[Index]: std::ops::Index
124124
[array]: ../types/array.md
125125
[const generic argument]: items.generics.const.argument
126+
[const block expression]: expr.block.const
126127
[constant expression]: ../const_eval.md#constant-expressions
127128
[constant item]: ../items/constant-items.md
128129
[inferred const]: items.generics.const.inferred

0 commit comments

Comments
 (0)