Skip to content

Commit cf51785

Browse files
authored
Rollup merge of #100872 - JanBeh:PR_vec_default_alloc_doc, r=fee1-dead
Add guarantee that Vec::default() does not alloc Currently `Vec::new()` is guaranteed to not allocate until elements are pushed onto the `Vec`, but such a guarantee is missing for `Vec`'s implementation of `Default::default`. This adds such a guarantee for `Vec::default()` to the API reference. See also [this discussion on URLO](https://users.rust-lang.org/t/guarantee-that-vec-default-does-not-allocate/79903).
2 parents de33a44 + 0227b71 commit cf51785

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

library/alloc/src/vec/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2928,6 +2928,8 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec<T, A> {
29282928
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
29292929
impl<T> const Default for Vec<T> {
29302930
/// Creates an empty `Vec<T>`.
2931+
///
2932+
/// The vector will not allocate until elements are pushed onto it.
29312933
fn default() -> Vec<T> {
29322934
Vec::new()
29332935
}

0 commit comments

Comments
 (0)