File tree 1 file changed +10
-3
lines changed
1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -16,14 +16,21 @@ brackets. This produces an array containing each of these values in the
16
16
order they are written.
17
17
18
18
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
20
20
` usize ` and be a [ constant expression] ,
21
21
such as a [ literal] ( ../tokens.md#literals ) or a [ constant
22
22
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
24
24
greater than 1 then this requires that the type of ` a ` is
25
25
[ ` 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 ) .
27
34
28
35
``` rust
29
36
[1 , 2 , 3 , 4 ];
You can’t perform that action at this time.
0 commit comments