Skip to content

Commit

Permalink
Rollup merge of rust-lang#108531 - Coca162:rustdoc-repeat-const-array…
Browse files Browse the repository at this point in the history
…, 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)
  • Loading branch information
matthiaskrgr authored Feb 28, 2023
2 parents d33bbfd + 22b65fc commit 62e6286
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions library/core/src/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,10 @@ mod prim_pointer {}
/// There are two syntactic forms for creating an array:
///
/// * A list with each element, i.e., `[x, y, z]`.
/// * A repeat expression `[x; N]`, which produces an array with `N` copies of `x`.
/// The type of `x` must be [`Copy`].
/// * A repeat expression `[expr; N]` where `N` is how many times to repeat `expr` in the array. `expr` must either be:
///
/// * A value of a type implementing the [`Copy`] trait
/// * A `const` value
///
/// Note that `[expr; 0]` is allowed, and produces an empty array.
/// This will still evaluate `expr`, however, and immediately drop the resulting value, so
Expand Down
6 changes: 4 additions & 2 deletions library/std/src/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,10 @@ mod prim_pointer {}
/// There are two syntactic forms for creating an array:
///
/// * A list with each element, i.e., `[x, y, z]`.
/// * A repeat expression `[x; N]`, which produces an array with `N` copies of `x`.
/// The type of `x` must be [`Copy`].
/// * A repeat expression `[expr; N]` where `N` is how many times to repeat `expr` in the array. `expr` must either be:
///
/// * A value of a type implementing the [`Copy`] trait
/// * A `const` value
///
/// Note that `[expr; 0]` is allowed, and produces an empty array.
/// This will still evaluate `expr`, however, and immediately drop the resulting value, so
Expand Down

0 comments on commit 62e6286

Please sign in to comment.