Skip to content

Commit 2455185

Browse files
authored
Rollup merge of #108531 - Coca162:rustdoc-repeat-const-array, r=thomcc
rustdoc: Show that repeated expression arrays can be made with constant values The [rust reference](https://doc.rust-lang.org/reference/expressions/array-expr.html) currently says that repeated values for arrays can be constant or `Copy` > repeat operand is [Copy](https://doc.rust-lang.org/reference/special-types-and-traits.html#copy) or that it must be a [path](https://doc.rust-lang.org/reference/expressions/path-expr.html) to a constant item This updates the rust documentation on primitive arrays to reflect what the rust reference says (and also compiler suggestions if you do not use a `const` item)
2 parents 371904b + 22b65fc commit 2455185

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

library/core/src/primitive_docs.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,10 @@ mod prim_pointer {}
587587
/// There are two syntactic forms for creating an array:
588588
///
589589
/// * A list with each element, i.e., `[x, y, z]`.
590-
/// * A repeat expression `[x; N]`, which produces an array with `N` copies of `x`.
591-
/// The type of `x` must be [`Copy`].
590+
/// * A repeat expression `[expr; N]` where `N` is how many times to repeat `expr` in the array. `expr` must either be:
591+
///
592+
/// * A value of a type implementing the [`Copy`] trait
593+
/// * A `const` value
592594
///
593595
/// Note that `[expr; 0]` is allowed, and produces an empty array.
594596
/// This will still evaluate `expr`, however, and immediately drop the resulting value, so

library/std/src/primitive_docs.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,10 @@ mod prim_pointer {}
587587
/// There are two syntactic forms for creating an array:
588588
///
589589
/// * A list with each element, i.e., `[x, y, z]`.
590-
/// * A repeat expression `[x; N]`, which produces an array with `N` copies of `x`.
591-
/// The type of `x` must be [`Copy`].
590+
/// * A repeat expression `[expr; N]` where `N` is how many times to repeat `expr` in the array. `expr` must either be:
591+
///
592+
/// * A value of a type implementing the [`Copy`] trait
593+
/// * A `const` value
592594
///
593595
/// Note that `[expr; 0]` is allowed, and produces an empty array.
594596
/// This will still evaluate `expr`, however, and immediately drop the resulting value, so

0 commit comments

Comments
 (0)