about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
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-5/+136
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-17/+55
2021-07-24Update std_collections_from_array stability versionbstrie-5/+5
2021-07-24Rollup merge of #87255 - RalfJung:miri-test-libcore, r=Mark-SimulacrumYuki Okushi-0/+4
better support for running libcore tests with Miri See https://github.com/rust-lang/miri-test-libstd/issues/4 for a description of the problem that this fixes. Thanks to `@hyd-dev` for suggesting this patch!
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-18better support for running libcore and liballoc tests with MiriRalf Jung-0/+4
2021-07-18Rollup merge of #87170 - xFrednet:clippy-5393-add-diagnostic-items, ↵Yuki Okushi-0/+2
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/+2
2021-07-15Added Arc::try_pinAlex Gaynor-1/+7
This helper is in line with other other allocation helpers on Arc.
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-8/+4
2021-07-06Rollup merge of #86852 - Amanieu:remove_doc_aliases, r=joshtriplettYuki Okushi-23/+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-04Stabilize `string_drain_as_str`Yuki Okushi-16/+14
2021-07-03Auto merge of #86810 - ojeda:alloc-gate, r=dtolnaybors-0/+12
alloc: `no_global_oom_handling`: disable `new()`s, `pin()`s, etc. They are infallible, and could not be actually used because they will trigger an error when monomorphized, but it is better to just remove them. Link: https://github.com/Rust-for-Linux/linux/pull/402 Suggested-by: Gary Guo <gary@garyguo.net> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-07-02alloc: `no_global_oom_handling`: disable `new()`s, `pin()`s, etc.Miguel Ojeda-0/+12
They are infallible, and could not be actually used because they will trigger an error when monomorphized, but it is better to just remove them. Link: https://github.com/Rust-for-Linux/linux/pull/402 Suggested-by: Gary Guo <gary@garyguo.net> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-07-02Rollup merge of #86714 - iwahbe:add-linked-list-cursor-end-methods, r=AmanieuGuillaume Gomez-0/+190
Add linked list cursor end methods I add several methods to `LinkedList::CursorMut` and `LinkedList::Cursor`. These methods allow you to access/manipulate the ends of a list via the cursor. This is especially helpful when scanning through a list and reordering. For example: ```rust let mut c = ll.back_cursor_mut(); let mut moves = 10; while c.current().map(|x| x > 5).unwrap_or(false) { let n = c.remove_current(); c.push_front(n); if moves > 0 { break; } else { moves -= 1; } } ``` I encountered this problem working on my bachelors thesis doing graph index manipulation. While this problem can be avoided by splicing, it is awkward. I asked about the problem [here](https://internals.rust-lang.org/t/linked-list-cursurmut-missing-methods/14921/4) and it was suggested I write a PR. All methods added consist of ```rust Cursor::front(&self) -> Option<&T>; Cursor::back(&self) -> Option<&T>; CursorMut::front(&self) -> Option<&T>; CursorMut::back(&self) -> Option<&T>; CursorMut::front_mut(&mut self) -> Option<&mut T>; CursorMut::back_mut(&mut self) -> Option<&mut T>; CursorMut::push_front(&mut self, elt: T); CursorMut::push_back(&mut self, elt: T); CursorMut::pop_front(&mut self) -> Option<T>; CursorMut::pop_back(&mut self) -> Option<T>; ``` #### Design decisions: I tried to remain as consistent as possible with what was already present for linked lists. The methods `front`, `front_mut`, `back` and `back_mut` are identical to their `LinkedList` equivalents. I tried to make the `pop_front` and `pop_back` methods work the same way (vis a vis the "ghost" node) as `remove_current`. I thought this was the closest analog. `push_front` and `push_back` do not change the "current" node, even if it is the "ghost" node. I thought it was most intuitive to say that if you add to the list, current will never change. Any feedback would be welcome :smile:
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-5/+136
2021-06-30Remove "length" doc aliasesAmanieu d'Antras-7/+0
2021-06-30Remove "delete" doc aliasesAmanieu d'Antras-2/+0
2021-06-30Remove alloc/malloc/calloc/realloc doc aliasesAmanieu d'Antras-14/+0
2021-06-30alloc: `RawVec<T, A>::shrink` can be in `no_global_oom_handling`.Miguel Ojeda-1/+0
Found in https://github.com/Rust-for-Linux/linux/pull/402. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
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-28Update to new bootstrap compilerMark Rousskov-2/+1
2021-06-26Auto merge of #86586 - Smittyvb:https-everywhere, r=petrochenkovbors-2/+2
Use HTTPS links where possible While looking at #86583, I wondered how many other (insecure) HTTP links were in `rustc`. This changes most other `http` links to `https`. While most of the links are in comments or documentation, there are a few other HTTP links that are used by CI that are changed to HTTPS. Notes: - I didn't change any to or in licences - Some links don't support HTTPS :( - Some `http` links were dead, in those cases I upgraded them to their new places (all of which used HTTPS)
2021-06-25Fix a few misspellings.Eric Huss-2/+2
2021-06-24Use `hash_one` to simplify some other doctestsScott McMurray-8/+3
2021-06-23Use HTTPS links where possibleSmitty-2/+2
2021-06-22Add comments around code where ordering is important due for panic-safetyThe8472-0/+8
Iterators contain arbitrary code which may panic. Unsafe code has to be careful to do its state updates at the right point between calls that may panic.
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-18Use `copy_nonoverlapping` to copy `bytes` in `String::insert_bytes`Paolo Barbolini-1/+1
2021-06-17Rollup merge of #85970 - jsha:remove-methods-implementors, r=GuillaumeGomezYuki Okushi-0/+4
Remove methods under Implementors on trait pages As discussed at https://github.com/rust-lang/rust/issues/84326#issuecomment-842652412. On a trait page, the "Implementors" section currently lists all methods of each implementor. That duplicates the method definitions on the trait itself, and is usually not very useful. So the implementors are collapsed by default. This PR changes rustdoc to just not render them at all. Any documentation specific to an implementor can be found by clicking through to the implementor's page. This moves the "portability" info inside the `<summary>` tags so it is still visible on trait pages (as originally implemented in #79201). That also means it will be visible on struct/enum pages when methods are collapsed. Add `#[doc(hidden)]` to all implementations of `Iterator::__iterator_get_unchecked` that didn't already have it. Otherwise, due to #86145, the structs/enums with those implementations would generate documentation for them, and that documentation would have a broken link into the Iterator page. Those links were already "broken" but not detected by the link-checker, because they pointed to one of the Implementors on the Iterator page, which happened to have the right anchor name. This reduces the Read trait's page size from 128kB to 68kB (uncompressed) and from 12,125 bytes to 9,989 bytes (gzipped Demo: https://hoffman-andrews.com/rust/remove-methods-implementors/std/string/struct.String.html#trait-implementations https://hoffman-andrews.com/rust/remove-methods-implementors/std/io/trait.Read.html#implementors r? `@GuillaumeGomez`
2021-06-17Rollup merge of #85663 - fee1-dead:document-arc-from, r=m-ou-seYuki Okushi-0/+14
Document Arc::from
2021-06-16Add doc(hidden) to all __iterator_get_uncheckedJacob Hoffman-Andrews-0/+4
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-17Rollup merge of #86140 - scottmcm:array-hash-facepalm, r=kennytmYuki Okushi-0/+17
Mention the `Borrow` guarantee on the `Hash` implementations for Arrays and `Vec` To remind people like me who forget about it and send PRs to make them different, and to (probably) get a test failure if the code is changed to no longer uphold it.