Skip to content

Commit 36edce3

Browse files
committed
Document array expression with a const.
1 parent b278478 commit 36edce3

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/expressions/array-expr.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ such as a [literal](../tokens.md#literals) or a [constant
2222
item](../items/constant-items.md). `[a; b]` creates an array containing `b`
2323
copies of the value of `a`. If the expression after the semi-colon has a value
2424
greater than 1 then this requires that the type of `a` is
25-
[`Copy`](../special-types-and-traits.md#copy).
25+
[`Copy`](../special-types-and-traits.md#copy), or `a` must be a path to a
26+
constant item.
2627

2728
```rust
2829
[1, 2, 3, 4];
2930
["a", "b", "c", "d"];
3031
[0; 128]; // array with 128 zeros
3132
[0u8, 0u8, 0u8, 0u8,];
3233
[[1, 0, 0], [0, 1, 0], [0, 0, 1]]; // 2D array
34+
const EMPTY: Vec<i32> = Vec::new();
35+
[EMPTY; 2];
3336
```
3437

3538
### Array expression attributes

0 commit comments

Comments
 (0)