about summary refs log tree commit diff
path: root/library/alloc/src/vec
AgeCommit message (Collapse)AuthorLines
2022-04-08add `<[[T; N]]>::flatten`, `<[[T; N]]>::flatten_mut`, and `Vec::<[T; ↵Cyborus04-0/+45
N]>::into_flattened`
2022-03-31Rollup merge of #95491 - faern:stabilize-vec_retain_mut, r=yaahcDylan DPC-3/+1
Stabilize feature vec_retain_mut on Vec and VecDeque Closes #90829
2022-03-31Rollup merge of #95298 - ↵Dylan DPC-7/+10
jhorstmann:fix-double-drop-of-allocator-in-vec-into-iter, r=oli-obk Fix double drop of allocator in IntoIter impl of Vec Fixes #95269 The `drop` impl of `IntoIter` reconstructs a `RawVec` from `buf`, `cap` and `alloc`, when that `RawVec` is dropped it also drops the allocator. To avoid dropping the allocator twice we wrap it in `ManuallyDrop` in the `InttoIter` struct. Note this is my first contribution to the standard library, so I might be missing some details or a better way to solve this.
2022-03-30Stabilize feature vec_retain_mut on Vec and VecDequeLinus Färnstrand-3/+1
2022-03-29Make the stdlib largely conform to strict provenance.Aria Beingessner-1/+1
Some things like the unwinders and system APIs are not fully conformant, this only covers a lot of low-hanging fruit.
2022-03-28Rollup merge of #95098 - shepmaster:vec-from-array-ref, r=dtolnayDylan DPC-0/+42
impl From<&[T; N]> and From<&mut [T; N]> for Vec<T> I really wanted to write: ```rust fn example(a: impl Into<Vec<u8>>) {} fn main() { example(b"raw"); } ```
2022-03-28Rollup merge of #95016 - janpaul123:patch-1, r=dtolnayDylan DPC-3/+7
Docs: make Vec::from_raw_parts documentation less strict This is my first PR; be gentle! In https://users.rust-lang.org/t/why-does-vec-from-raw-parts-require-same-size-and-not-same-size-capacity/73036/2?u=janpaul123 it was suggested to me that I should make a PR to make the documentation of `Vec::from_raw_parts` less strict, since we don't require `T` to have the same size, just `size_of::<T>() * capacity` to be the same, since that is what results in `Layout::size` being the same in `dealloc`, which is really what matters. Also in https://users.rust-lang.org/t/why-does-vec-from-raw-parts-require-same-size-and-not-same-size-capacity/73036/8?u=janpaul123 it was suggested that it's better to use `slice::from_raw_parts`, which I think is useful advise that could also be mentioned in the docs, so I added that too. Let me know what you think! :)
2022-03-28Rollup merge of #93755 - ↵Dylan DPC-1/+1
ChayimFriedman2:allow-comparing-vecs-with-different-allocators, r=dtolnay Allow comparing `Vec`s with different allocators using `==` See https://stackoverflow.com/q/71021633/7884305. I did not changed the `PartialOrd` impl too because it was not generic already (didn't support `Vec<T> <=> Vec<U> where T: PartialOrd<U>`). Does it needs tests? I don't think this will hurt type inference much because the default allocator is usually not inferred (`new()` specifies it directly, and even with other allocators, you pass the allocator to `new_in()` so the compiler usually knows the type). I think this requires FCP since the impls are already stable.
2022-03-27Support arrays of zeros in Vec's __rust_alloc_zeroed optimizationScott McMurray-1/+8
2022-03-25Use ManuallyDrop::take instead of into_innerJörn Horstmann-1/+1
Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>
2022-03-25Fix double drop of allocator in IntoIter impl of VecJörn Horstmann-7/+10
2022-03-23fix some links, clarify documentation based on review feedbackThe 8472-12/+19
2022-03-22Remove impossible panic note from `Vec::append`Tobias Bucher-1/+1
Neither the number of elements in a vector can overflow a `usize`, nor can the amount of elements in two vectors.
2022-03-22rename internal helper trait AsIntoIter to AsVecIntoIterThe 8472-8/+8
2022-03-21add module-level documentation for vec's in-place iterationThe8472-20/+157
2022-03-21move AsIntoIter helper trait and mark it as unsafeThe8472-10/+13
2022-03-21rename module to better reflect its purposeThe8472-1/+1
2022-03-18impl From<&[T; N]> and From<&mut [T; N]> for Vec<T>Jake Goulding-0/+42
2022-03-16Docs: make Vec::from_raw_parts documentation less strictJP Posma-3/+7
This is my first PR; be gentle! In https://users.rust-lang.org/t/why-does-vec-from-raw-parts-require-same-size-and-not-same-size-capacity/73036/2?u=janpaul123 it was suggested to me that I should make a PR to make the documentation of `Vec::from_raw_parts` less strict, since we don't require `T` to have the same size, just `size_of::<T>() * capacity` to be the same, since that is what results in `Layout::size` being the same in `dealloc`, which is really what matters. Also in https://users.rust-lang.org/t/why-does-vec-from-raw-parts-require-same-size-and-not-same-size-capacity/73036/8?u=janpaul123 it was suggested that it's better to use `slice::from_raw_parts`, which I think is useful advise that could also be mentioned in the docs, so I added that too. Let me know what you think! :)
2022-03-11Rollup merge of #94826 - allgoewer:fix-retain-documentation, r=yaahcDylan DPC-1/+1
Improve doc wording for retain on some collections I found the documentation wording on the various retain methods on many collections to be unusual. I tried to invert the relation by switching `such that` with `for which` .
2022-03-11Improve doc wording for retain on some collectionsMaik Allgöwer-1/+1
2022-03-10Use implicit capture syntax in format_argsT-O-R-U-S-7/+7
This updates the standard library's documentation to use the new syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored).
2022-02-28Rollup merge of #92399 - Veeupup:fix_vec_typo, r=Dylan-DPCMatthias Krüger-2/+2
fix typo in btree/vec doc: Self -> self this pr fixes #92345 the documentation refers to the object the method is called for, not the type, so it should be using the lower case self.
2022-02-19Collections: improve the documentation of drain membersStein Somers-7/+12
2022-02-17Rollup merge of #89869 - kpreid:from-doc, r=yaahcMatthias Krüger-4/+5
Add documentation to more `From::from` implementations. For users looking at documentation through IDE popups, this gives them relevant information rather than the generic trait documentation wording “Performs the conversion”. For users reading the documentation for a specific type for any reason, this informs them when the conversion may allocate or copy significant memory versus when it is always a move or cheap copy. Notes on specific cases: * The new documentation for `From<T> for T` explains that it is not a conversion at all. * Also documented `impl<T, U> Into<U> for T where U: From<T>`, the other central blanket implementation of conversion. * The new documentation for construction of maps and sets from arrays of keys mentions the handling of duplicates. Future work could be to do this for *all* code paths that convert an iterable to a map or set. * I did not add documentation to conversions of a specific error type to a more general error type. * I did not add documentation to unstable code. This change was prepared by searching for the text "From<... for" and so may have missed some cases that for whatever reason did not match. I also looked for `Into` impls but did not find any worth documenting by the above criteria.
2022-02-08Allow comparing `Vec`s with different allocators using `==`Chayim Refael Friedman-1/+1
2022-01-19Improve estimation of capacity in Vec::from_iterAngelicosPhosphoros-2/+8
Closes #48994
2022-01-18Rollup merge of #93016 - Amanieu:vec_spare_capacity, r=Mark-SimulacrumMatthias Krüger-3/+1
Stabilize vec_spare_capacity Closes #75017
2022-01-17Stabilize vec_spare_capacityAmanieu d'Antras-3/+1
Closes #75017
2022-01-16Docs: recommend VecDeque instead of Vec::remove(0)Kornel-1/+9
2022-01-13Add Sync bound to allocator parameter in vec::IntoIterMichael Goulet-1/+1
2022-01-08Auto merge of #92068 - fee1-dead:libcore2021, r=m-ou-sebors-3/+0
Switch all libraries to the 2021 edition The fix for https://github.com/rust-lang/rust/issues/88638#issuecomment-996620107 is to simply add const-stability for these functions. r? `@m-ou-se` Closes #88638.
2022-01-06remove unused ExtendDefault structFrank Steffahn-10/+0
2022-01-01Rollup merge of #92463 - thomcc:thats-not-how-its-pronounced, r=joshtriplettMatthias Krüger-1/+1
Remove pronunciation guide from Vec<T> I performed an extremely scientific poll on twitter, and determined this is not how it's pronounced: https://twitter.com/at_tcsc/status/1476643344285581315
2022-01-01Rollup merge of #92097 - saethlin:split-without-deref, r=the8472Matthias Krüger-2/+7
Implement split_at_spare_mut without Deref to a slice so that the spare slice is valid ~I'm not sure I understand what's going on here correctly. And I'm pretty sure this safety comment needs to be changed. I'm just referring to the same thing that `as_mut_ptr_range` does.~ (Thanks `@RalfJung` for the guidance and clearing things up) I tried to run https://github.com/rust-lang/miri-test-libstd on alloc with -Zmiri-track-raw-pointers, and got a failure on the test `vec::test_extend_from_within`. I minimized the test failure into this program: ```rust #![feature(vec_split_at_spare)] fn main() { Vec::<i32>::with_capacity(1).split_at_spare_mut(); } ``` The problem is that the existing implementation is actually getting a pointer range where both pointers are derived from the initialized region of the Vec's allocation, but we need the second one to be valid for the region between len and capacity. (thanks Ralf for clearing this up)
2021-12-31Clarify safety commentBen Kimock-0/+2
2021-12-31Remove pronunciation guide from Vec<T>Thom Chiovoloni-1/+1
2021-12-29fix typo in btree/vec doc: Self -> selfVeeupup-2/+2
2021-12-24Remove `maybe_uninit_extra` feature from Vec docsShadlock0133-2/+2
In `Vec`, two doc tests are using `MaybeUninit::write` , stabilized in 1.55. This makes docs' usage of `maybe_uninit_extra` feature unnecessary.
2021-12-23Bless a few testsDeadbeef-3/+0
2021-12-19Implement split_at_spare_mut directlyBen Kimock-2/+5
The previous implementation used slice::as_mut_ptr_range to derive the pointer for the spare capacity slice. This is invalid, because that pointer is derived from the initialized region, so it does not have provenance over the uninitialized region.
2021-12-19paniced -> panickedr00ster-1/+1
2021-12-18Update example code for Vec::splice to change the lengthajtribick-5/+5
2021-12-16Auto merge of #91527 - the8472:retain-opt, r=dtolnaybors-32/+29
Optimize `vec::retain` performance This simply moves the loops into the inner function which leads to better results. ``` old: test vec::bench_retain_100000 ... bench: 203,828 ns/iter (+/- 2,101) test vec::bench_retain_iter_100000 ... bench: 63,324 ns/iter (+/- 12,305) test vec::bench_retain_whole_100000 ... bench: 42,989 ns/iter (+/- 291) new: test vec::bench_retain_100000 ... bench: 42,180 ns/iter (+/- 451) test vec::bench_retain_iter_100000 ... bench: 65,167 ns/iter (+/- 11,971) test vec::bench_retain_whole_100000 ... bench: 33,736 ns/iter (+/- 12,404) ``` Measured on x86_64-unknown-linux-gnu, Zen2 Fixes #91497
2021-12-11Fix zero-sized reference to deallocated memoryThe 8472-4/+6
fixes #91772
2021-12-11Auto merge of #91761 - matthiaskrgr:rollup-bjowmvz, r=matthiaskrgrbors-1/+1
Rollup of 11 pull requests Successful merges: - #91668 (Remove the match on `ErrorKind::Other`) - #91678 (Add tests fixed by #90023) - #91679 (Move core/stream/stream/mod.rs to core/stream/stream.rs) - #91681 (fix typo in `intrinsics::raw_eq` docs) - #91686 (Fix `Vec::reserve_exact` documentation) - #91697 (Delete Utf8Lossy::from_str) - #91706 (Add unstable book entries for parts of asm that are not being stabilized) - #91709 (Replace iterator-based set construction by *Set::From<[T; N]>) - #91716 (Improve x.py logging and defaults a bit more) - #91747 (Add pierwill to .mailmap) - #91755 (Fix since attribute for const_linked_list_new feature) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-12-10Rollup merge of #91686 - dalcde:patch-1, r=dtolnayMatthias Krüger-1/+1
Fix `Vec::reserve_exact` documentation The documentation previously said the new capacity cannot overflow `usize`, but in fact it cannot exceed `isize::MAX`.
2021-12-10Rollup merge of #91524 - rukai:fix_extend_from_slice_docs, r=dtolnayMatthias Krüger-1/+1
Fix Vec::extend_from_slice docs `other` is a slice not a vector.
2021-12-09Auto merge of #85157 - the8472:drain-drop-in-place, r=Mark-Simulacrumbors-14/+39
replace vec::Drain drop loops with drop_in_place The `Drain::drop` implementation came up in https://github.com/rust-lang/rust/pull/82185#issuecomment-789584796 as potentially interfering with other optimization work due its widespread use somewhere in `println!` `@rustbot` label T-libs-impl
2021-12-08Fix `Vec::reserve_exact` documentationDexter Chua-1/+1
The documentation previously said the new capacity cannot overflow `usize`, but in fact it cannot exceed `isize::MAX`.