Skip to content

Commit e031b14

Browse files
committed
Document array expression with a const.
1 parent 8027bc8 commit e031b14

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/expressions/array-expr.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ separated by a semicolon. The expression after the `;` must have type `usize`
1919
and be a [constant expression], such as a [literal] or a [constant item]. `[a;
2020
b]` creates an array containing `b` copies of the value of `a`. If the
2121
expression after the semicolon has a value greater than 1 then this requires
22-
that the type of `a` is [`Copy`].
22+
that the type of `a` is [`Copy`], or `a` must be a path to a constant item.
2323

2424
```rust
2525
[1, 2, 3, 4];
2626
["a", "b", "c", "d"];
2727
[0; 128]; // array with 128 zeros
2828
[0u8, 0u8, 0u8, 0u8,];
2929
[[1, 0, 0], [0, 1, 0], [0, 0, 1]]; // 2D array
30+
const EMPTY: Vec<i32> = Vec::new();
31+
[EMPTY; 2];
3032
```
3133

3234
### Array expression attributes

0 commit comments

Comments
 (0)