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).
This commit is contained in:
commit
4ed8fa4759
1 changed files with 2 additions and 0 deletions
|
@ -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")]
|
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
|
||||||
impl<T> const Default for Vec<T> {
|
impl<T> const Default for Vec<T> {
|
||||||
/// Creates an empty `Vec<T>`.
|
/// Creates an empty `Vec<T>`.
|
||||||
|
///
|
||||||
|
/// The vector will not allocate until elements are pushed onto it.
|
||||||
fn default() -> Vec<T> {
|
fn default() -> Vec<T> {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue