about summary refs log tree commit diff
path: root/library/alloc/src/collections
AgeCommit message (Collapse)AuthorLines
2021-08-08Auto merge of #86879 - YohDeadfall:stabilize-vec-shrink-to, r=dtolnaybors-4/+2
Stabilize Vec<T>::shrink_to This PR stabilizes `shrink_to` feature and closes the corresponding issue. The second point was addressed already, and no `panic!` should occur. Closes #56431.
2021-08-08Bump shrink_to stabilization to Rust 1.56David Tolnay-2/+2
2021-08-07Inline from of TryReserveErrorKindKornel-0/+1
2021-08-07Auto merge of #87408 - kornelski:try_reserve_error, r=yaahcbors-7/+45
Hide allocator details from TryReserveError I think there's [no need for TryReserveError to carry detailed information](https://github.com/rust-lang/rust/issues/48043#issuecomment-825139280), but I wouldn't want that issue to delay stabilization of the `try_reserve` feature. So I'm proposing to stabilize `try_reserve` with a `TryReserveError` as an opaque structure, and if needed, expose error details later. This PR moves the `enum` to an unstable inner `TryReserveErrorKind` that lives under a separate feature flag. `TryReserveErrorKind` could possibly be left as an implementation detail forever, and the `TryReserveError` get methods such as `allocation_size() -> Option<usize>` or `layout() -> Option<Layout>` instead, or the details could be dropped completely to make try-reserve errors just a unit struct, and thus smaller and cheaper.
2021-08-05alloc: Use intra doc links for the reserve functionest31-1/+3
The sentence exists to highlight the existence of a performance footgun of repeated calls of the reserve_exact function.
2021-08-02BTree: merge the complication introduced by #81486 and #86031Stein Somers-56/+56
2021-08-01Auto merge of #86031 - ssomers:btree_lazy_iterator, r=Mark-Simulacrumbors-68/+171
BTree: lazily locate leaves in rangeless iterators BTree iterators always locate both the first and last leaf edge and often only need either one, i.e., whenever they are traversed in a single direction, like in for-loops and in the common use of `iter().next()` or `iter().next_back()` to retrieve the first or last key/value-pair (#62924). It's fairly easy to avoid because the iterators with this disadvantage already are quite separate from other iterators. r? `@Mark-Simulacrum`
2021-07-30Rollup merge of #87574 - cuviper:retain-examples, r=joshtriplettYuki Okushi-3/+4
Update the examples in `String` and `VecDeque::retain` The examples added in #60396 used a "clever" post-increment hack, unrelated to the actual point of the examples. That hack was found [confusing] in the users forum, and #81811 already changed the `Vec` example to use a more direct iterator. This commit changes `String` and `VecDeque` in the same way for consistency. [confusing]: https://users.rust-lang.org/t/help-understand-strange-expression/62858
2021-07-29Fix may not to appropriate might not or must notAli Malik-2/+2
2021-07-28Update the examples in `String` and `VecDeque::retain`Josh Stone-3/+4
The examples added in #60396 used a "clever" post-increment hack, unrelated to the actual point of the examples. That hack was found [confusing] in the users forum, and #81811 already changed the `Vec` example to use a more direct iterator. This commit changes `String` and `VecDeque` in the same way for consistency. [confusing]: https://users.rust-lang.org/t/help-understand-strange-expression/62858
2021-07-28Remove redundant bounds on get_unchecked for vec_deque iterators, and run fmtFrank Steffahn-10/+4
2021-07-28Add TrustedRandomAccessNoCoerce supertrait without requirements or ↵Frank Steffahn-4/+12
guarantees about subtype coercions Update all the TrustedRandomAccess impls to also implement the new supertrait
2021-07-25Auto merge of #86595 - a1phyr:allocator_api_for_vecdeque, r=Amanieubors-74/+137
Add support for custom allocator in `VecDeque` This follows the [roadmap](https://github.com/rust-lang/wg-allocators/issues/7) of the allocator WG to add custom allocators to collections. `@rustbot` modify labels: +A-allocators +T-libs
2021-07-24Auto merge of #84111 - bstrie:hashfrom, r=joshtriplettbors-1/+131
Stabilize `impl From<[(K, V); N]> for HashMap` (and friends) In addition to allowing HashMap to participate in Into/From conversion, this adds the long-requested ability to use constructor-like syntax for initializing a HashMap: ```rust let map = HashMap::from([ (1, 2), (3, 4), (5, 6) ]); ``` This addition is highly motivated by existing precedence, e.g. it is already possible to similarly construct a Vec from a fixed-size array: ```rust let vec = Vec::from([1, 2, 3]); ``` ...and it is already possible to collect a Vec of tuples into a HashMap (and vice-versa): ```rust let vec = Vec::from([(1, 2)]); let map: HashMap<_, _> = vec.into_iter().collect(); let vec: Vec<(_, _)> = map.into_iter().collect(); ``` ...and of course it is likewise possible to collect a fixed-size array of tuples into a HashMap ([but not vice-versa just yet](https://github.com/rust-lang/rust/issues/81615)): ```rust let arr = [(1, 2)]; let map: HashMap<_, _> = std::array::IntoIter::new(arr).collect(); ``` Therefore this addition seems like a no-brainer. As for any impl, this would be insta-stable.
2021-07-24Hide allocator details from TryReserveErrorKornel-7/+45
2021-07-24Update std_collections_from_array stability versionbstrie-5/+5
2021-07-24Rollup merge of #86790 - janikrabe:retain-iter-order-doc, r=m-ou-seYuki Okushi-0/+2
Document iteration order of `retain` functions For `HashSet` and `HashMap`, this simply copies the comment from `BinaryHeap::retain`. For `BTreeSet` and `BTreeMap`, this adds an additional guarantee that wasn't previously documented. I think that because these data structures are inherently ordered and other functions guarantee ordered iteration, it makes sense to provide this guarantee for `retain` as well.
2021-07-23Add `#[unstable]` on new functionsBenoît du Garreau-2/+2
2021-07-23Add unstable attribute for `A` in `Drain` and `IntoIter`Benoît du Garreau-2/+9
2021-07-23Add support for custom allocator in `VecDeque`Benoît du Garreau-74/+130
2021-07-21Remove unsound TrustedRandomAccess implementationsFrank Steffahn-29/+1
Removes the implementations that depend on the user-definable trait `Copy`. Only fix regressions to ensure merge in 1.55: Does not modify `vec::IntoIter`.
2021-07-18Rollup merge of #87170 - xFrednet:clippy-5393-add-diagnostic-items, ↵Yuki Okushi-0/+1
r=Manishearth,oli-obk Add diagnostic items for Clippy This adds a bunch of diagnostic items to `std`/`core`/`alloc` functions, structs and traits used in Clippy. The actual refactorings in Clippy to use these items will be done in a different PR in Clippy after the next sync. This PR doesn't include all paths Clippy uses, I've only gone through the first 85 lines of Clippy's [`paths.rs`](https://github.com/rust-lang/rust-clippy/blob/ecf85f4bdc319f9d9d853d1fff68a8a25e64c7a8/clippy_utils/src/paths.rs) (after rust-lang/rust-clippy#7466) to get some feedback early on. I've also decided against adding diagnostic items to methods, as it would be nicer and more scalable to access them in a nicer fashion, like adding a `is_diagnostic_assoc_item(did, sym::Iterator, sym::map)` function or something similar (Suggested by `@camsteffen` [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/147480-t-compiler.2Fwg-diagnostics/topic/Diagnostic.20Item.20Naming.20Convention.3F/near/225024603)) There seems to be some different naming conventions when it comes to diagnostic items, some use UpperCamelCase (`BinaryHeap`) and some snake_case (`hashmap_type`). This PR uses UpperCamelCase for structs and traits and snake_case with the module name as a prefix for functions. Any feedback on is this welcome. cc: rust-lang/rust-clippy#5393 r? `@Manishearth`
2021-07-15Added diagnostic items to structs and traits for ClippyxFrednet-0/+1
2021-07-12Make BTreeSet::split_off name elements like other set methods doStein Somers-4/+4
2021-07-08BTree: lazily locate leaves in rangeless iteratorsStein Somers-68/+171
2021-07-08Auto merge of #86982 - GuillaumeGomez:rollup-7sbye3c, r=GuillaumeGomezbors-9/+11
Rollup of 8 pull requests Successful merges: - #84961 (Rework SESSION_GLOBALS API) - #86726 (Use diagnostic items instead of lang items for rfc2229 migrations) - #86789 (Update BTreeSet::drain_filter documentation) - #86838 (Checking that function is const if marked with rustc_const_unstable) - #86903 (Fix small headers display) - #86913 (Document rustdoc with `--document-private-items`) - #86957 (Update .mailmap file) - #86971 (mailmap: Add alternative addresses for myself) Failed merges: - #86869 (Account for capture kind in auto traits migration) r? `@ghost` `@rustbot` modify labels: rollup
2021-07-08Rollup merge of #86789 - janikrabe:btreeset-drainfilter-doc, r=kennytmGuillaume Gomez-9/+11
Update BTreeSet::drain_filter documentation This commit makes the documentation of `BTreeSet::drain_filter` more consistent with that of `BTreeMap::drain_filter` after the changes in f0b8166870bd73a872642f090ae6b88e2bef922a. In particular, this explicitly documents the iteration order.
2021-07-08Auto merge of #86520 - ssomers:btree_iterators_checked_unwrap, r=Mark-Simulacrumbors-24/+10
BTree: consistently avoid unwrap_unchecked in iterators Some iterator support functions named `_unchecked` internally use `unwrap`, some use `unwrap_unchecked`. This PR tries settling on `unwrap`. #86195 went up the same road but travelled way further and doesn't seem successful. r? `@Mark-Simulacrum`
2021-07-08Rollup merge of #86917 - notriddle:notriddle/from-try-reserve-error, r=JohnTitorYuki Okushi-0/+1
Add doc comment for `impl From<LayoutError> for TryReserveError`
2021-07-06Add doc comment for `impl From<LayoutError> for TryReserveError`Michael Howell-0/+1
2021-07-06Stabilize Vec<T>::shrink_toYoh Deadfall-4/+2
2021-07-06Rollup merge of #86852 - Amanieu:remove_doc_aliases, r=joshtriplettYuki Okushi-7/+0
Remove some doc aliases As per the new doc alias policy in https://github.com/rust-lang/std-dev-guide/pull/25, this removes some controversial doc aliases: - `malloc`, `alloc`, `realloc`, etc. - `length` (alias for `len`) - `delete` (alias for `remove` in collections and also file/directory deletion) r? `@joshtriplett`
2021-07-01Document iteration order of `retain` functionsJanik Rabe-0/+2
For `HashSet` and `HashMap`, this simply copies the comment from `BinaryHeap::retain`. For `BTreeSet` and `BTreeMap`, this adds an additional guarantee that wasn't previously documented. I think that because these data structures are inherently ordered and other functions guarantee ordered iteration, it makes sense to provide this guarantee for `retain` as well.
2021-07-01Update BTreeSet::drain_filter documentationJanik Rabe-9/+11
This commit makes the documentation of `BTreeSet::drain_filter` more consistent with that of `BTreeMap::drain_filter` after the changes in f0b8166870bd73a872642f090ae6b88e2bef922a. In particular, this explicitly documents the iteration order.
2021-07-01Implement changes suggested by @AmanieuIan Wahbe-10/+29
2021-06-30impl From<[(K, V); N]> for std::collectionsbstrie-1/+131
2021-06-30Remove "length" doc aliasesAmanieu d'Antras-5/+0
2021-06-30Remove "delete" doc aliasesAmanieu d'Antras-2/+0
2021-06-29Add non-mutable methods to `Cursor`Ian Wahbe-0/+17
2021-06-29add head/tail methods to linked list mutable cursorIan Wahbe-0/+154
2021-06-25Fix a few misspellings.Eric Huss-2/+2
2021-06-21BTree: consistently avoid unwrap_unchecked in iteratorsStein Somers-24/+10
2021-06-20Auto merge of #85980 - ssomers:btree_cleanup_LeafRange, r=Mark-Simulacrumbors-51/+111
BTree: encapsulate LeafRange better & some debug asserts Looking at iterators again, I think #81937 didn't house enough code in `LeafRange`. Moving the API boundary a little makes things more local in navigate.rs and less complicated in map.rs. r? `@Mark-Simulacrum`
2021-06-16Add doc(hidden) to all __iterator_get_uncheckedJacob Hoffman-Andrews-0/+3
This method on the Iterator trait is doc(hidden), and about half of implementations were doc(hidden). This adds the attribute to the remaining implementations.
2021-06-09BTree: encapsulate LeafRange better & some debug assertsStein Somers-51/+111
2021-06-06Rollup merge of #85930 - mominul:array_into_iter, r=m-ou-seYuki Okushi-2/+1
Update standard library for IntoIterator implementation of arrays This PR partially resolves issue #84513 of updating the standard library part. I haven't found any remaining doctest examples which are using iterators over e.g. &i32 instead of just i32 in the standard library. Can anyone point me to them if there's remaining any? Thanks! r? ```@m-ou-se```
2021-06-02Stabilize VecDeque::partition_point.Mara Bos-2/+1
2021-06-02Bump vecdeque_binary_search stabilization to 1.54.Mara Bos-3/+3
2021-06-02Bumped `vecdeque_binary_search` stabilization version to 1.53.0SOFe-3/+3
2021-06-02Stabilize `vecdeque_binary_search`SOFe-7/+3