diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-08-22 20:34:16 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-22 20:34:16 +0530 |
| commit | 4ed8fa47592ade04e388bc527c26d09c651b6455 (patch) | |
| tree | 98d9c646995d871fd4c68aa8e4ad564c50e5e3a0 /library/alloc/src | |
| parent | 58d23737a6d77c88af6b9b600058877910db1bff (diff) | |
| parent | 0227b71865b982a309a0f8992e33042a4d23ae0d (diff) | |
| download | rust-4ed8fa47592ade04e388bc527c26d09c651b6455.tar.gz rust-4ed8fa47592ade04e388bc527c26d09c651b6455.zip | |
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).
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/vec/mod.rs | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index fe983274b5c..2c786fd511e 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2928,6 +2928,8 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec<T, A> { #[rustc_const_unstable(feature = "const_default_impls", issue = "87864")] impl<T> const Default for Vec<T> { /// Creates an empty `Vec<T>`. + /// + /// The vector will not allocate until elements are pushed onto it. fn default() -> Vec<T> { Vec::new() } |
