Skip to content

Commit a2e5a14

Browse files
committed
Document [a; 0] behavior.
1 parent e031b14 commit a2e5a14

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/expressions/array-expr.md

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ 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
2222
that the type of `a` is [`Copy`], or `a` must be a path to a constant item.
2323

24+
When the repeat expression `a` is a constant item, it is evaluated `b` times.
25+
If `b` is 0, the constant item is not evaluated at all. For expressions that
26+
are not a constant item, it is evaluated exactly once, and then the result is
27+
copied `b` times.
28+
29+
> **Note:** In the case where `b` is 0, and `a` is a non-constant item, there
30+
> is currently a bug in `rustc` where the value `a` is evaluated but not
31+
> dropped, thus causing a leak. See [issue
32+
> #74836](https://github.com/rust-lang/rust/issues/74836).
33+
2434
```rust
2535
[1, 2, 3, 4];
2636
["a", "b", "c", "d"];

0 commit comments

Comments
 (0)