Skip to content

Commit 3d5a774

Browse files
committed
Document [a; 0] behavior.
1 parent 36edce3 commit 3d5a774

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/expressions/array-expr.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,21 @@ brackets. This produces an array containing each of these values in the
1616
order they are written.
1717

1818
Alternatively there can be exactly two expressions inside the brackets,
19-
separated by a semi-colon. The expression after the `;` must have type
19+
separated by a semicolon. The expression after the `;` must have type
2020
`usize` and be a [constant expression],
2121
such as a [literal](../tokens.md#literals) or a [constant
2222
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
23+
copies of the value of `a`. If the expression `b` after the semicolon has a value
2424
greater than 1 then this requires that the type of `a` is
2525
[`Copy`](../special-types-and-traits.md#copy), or `a` must be a path to a
26-
constant item.
26+
constant item. When `b` evaluates to 0, the expression `a` is evaluated once
27+
unless it is a path to a constant item, in which case the constant is not
28+
instantiated.
29+
30+
> **Note:** In the case where `b` is 0, and `a` is a non-const expression,
31+
> there is currently a bug in `rustc` where the value `a` is evaluated but not
32+
> dropped, thus causing a leak. See [issue
33+
> #74836](https://github.com/rust-lang/rust/issues/74836).
2734
2835
```rust
2936
[1, 2, 3, 4];

0 commit comments

Comments
 (0)