Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc(array,vec): add notes about side effects when empty-initializing #79918

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions library/alloc/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
/// to the same boxed integer value, not five references pointing to independently
/// boxed integers.
///
/// Also, note that `[T; 0]` is a valid initializer. This will initialize (or call)
/// `T` but not populate the vector with it, so be mindful of side effects.
woodruffw marked this conversation as resolved.
Show resolved Hide resolved
///
/// [`Vec`]: crate::vec::Vec
#[cfg(not(test))]
#[macro_export]
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,9 @@ mod prim_pointer {}
/// * A repeat expression `[x; N]`, which produces an array with `N` copies of `x`.
/// The type of `x` must be [`Copy`].
///
/// Note that `[x; 0]` is a valid repeat expression. This will produce an empty array
/// but will also initialize (or call) `x`, which may produce side effects.
///
/// Arrays of *any* size implement the following traits if the element type allows it:
///
/// - [`Copy`]
Expand Down