Skip to content

Commit 0227b71

Browse files
committed
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.
1 parent a9bb589 commit 0227b71

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
@@ -2927,6 +2927,8 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec<T, A> {
29272927
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
29282928
impl<T> const Default for Vec<T> {
29292929
/// Creates an empty `Vec<T>`.
2930+
///
2931+
/// The vector will not allocate until elements are pushed onto it.
29302932
fn default() -> Vec<T> {
29312933
Vec::new()
29322934
}

0 commit comments

Comments
 (0)