about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
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-10Rollup merge of #91482 - ↵Matthias Krüger-4/+5
JosephTLyons:update-HashMap-and-BTreeMap-documentation, r=yaahc Update documentation to use `from()` to initialize `HashMap`s and `BTreeMap`s As of Rust 1.56, `HashMap` and `BTreeMap` both have associated `from()` functions. I think using these in the documentation cleans things up a bit. It allows us to remove some of the `mut`s and avoids the Initialize-Then-Modify anti-pattern.
2021-12-10Fix since attribute for const_linked_list_new featureMartin Fischer-1/+1
https://github.com/rust-lang/rust/pull/63684 was merged for 1.39 not 1.32
2021-12-10BTree: improve public descriptions and commentsStein Somers-55/+58
2021-12-10BTree: assert presence of derived functionsStein Somers-0/+32
2021-12-10BTree: rename compile-time assertions to match library/alloc/testsStein Somers-6/+6
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-09Replace iterator-based set construction by *Set::From<[T; N]>Júnior Bassani-19/+18
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`.
2021-12-09Use `*mut [T]` instead of `[MaybeUninit<T>]`The 8472-7/+5
2021-12-08Use spare_capacity_mut instead of invalid unchecked indexingBen Kimock-2/+10
2021-12-07Rollup merge of #91547 - TennyZhuang:suggest_try_reserve, r=scottmcmMatthias Krüger-6/+6
Suggest try_reserve in try_reserve_exact During developing #91529 , I found that `try_reserve_exact` suggests `reserve` for further insertions. I think it's a mistake by copy&paste, `try_reserve` is better here.
2021-12-05Auto merge of #88611 - m-ou-se:array-into-iter-new-deprecate, r=joshtriplettbors-7/+7
Deprecate array::IntoIter::new.
2021-12-05doc: suggest try_reserve in try_reserve_exactTennyZhuang-6/+6
Signed-off-by: TennyZhuang <zty0826@gmail.com>
2021-12-05Rollup merge of #91215 - GuillaumeGomez:vec-deque-retain-mut, r=m-ou-seMatthias Krüger-3/+34
Implement VecDeque::retain_mut Part of https://github.com/rust-lang/rust/issues/90829. In https://github.com/rust-lang/rust/pull/90772, someone suggested that `retain_mut` should also be implemented on `VecDeque`. I think that it follows the same logic (coherency). So first: is it ok? Second: should I create a new feature for it or can we put it into the same one? r? `@joshtriplett`
2021-12-04Use IntoIterator for array impl everywhere.Mara Bos-7/+7
2021-12-04Add documentation to more `From::from` implementations.Kevin Reid-4/+13
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. * 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.
2021-12-04Optimize vec::retain performanceThe 8472-32/+29
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) ```
2021-12-05Fix Vec::extend_from_slice docsLucas Kent-1/+1
2021-12-04Rollup merge of #90851 - ibraheemdev:downcast-unchecked, r=scottmcmMatthias Krüger-28/+109
Add unchecked downcast methods ```rust impl dyn Any (+ Send + Sync) { pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T; pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T; } impl<A: Allocator> Box<dyn Any (+ Send + Sync), A> { pub unsafe fn downcast_unchecked<T: Any>(&self) -> Box<T, A>; } ```
2021-12-03fix stability annotations for `Box::downcast`Ibraheem Ahmed-2/+2
2021-12-03Auto merge of #91486 - matthiaskrgr:rollup-699fo18, r=matthiaskrgrbors-0/+36
Rollup of 10 pull requests Successful merges: - #88906 (Implement write() method for Box<MaybeUninit<T>>) - #90269 (Make `Option::expect` unstably const) - #90854 (Type can be unsized and uninhabited) - #91170 (rustdoc: preload fonts) - #91273 (Fix ICE #91268 by checking that the snippet ends with a `)`) - #91381 (Android: -ldl must appear after -lgcc when linking) - #91453 (Document Windows TLS drop behaviour) - #91462 (Use try_normalize_erasing_regions in needs_drop) - #91474 (suppress warning about set_errno being unused on DragonFly) - #91483 (Sync rustfmt subtree) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-12-03Rollup merge of #88906 - Kixunil:box-maybe-uninit-write, r=dtolnayMatthias Krüger-0/+36
Implement write() method for Box<MaybeUninit<T>> This adds method similar to `MaybeUninit::write` main difference being it returns owned `Box`. This can be used to elide copy from stack safely, however it's not currently tested that the optimization actually occurs. Analogous methods are not provided for `Rc` and `Arc` as those need to handle the possibility of sharing. Some version of them may be added in the future. This was discussed in #63291 which this change extends.
2021-12-03Auto merge of #91339 - cbarrete:vecdeque-remove-grow-check, r=Mark-Simulacrumbors-9/+11
Remove unnecessary check in VecDeque::grow All callers already check that the buffer is full before calling `grow()`. This is where it makes the most sense, since `grow()` is `inline(never)` and we don't want to pay for a function call just for that check. It could also be argued that it would be correct to call `grow()` even if the buffer wasn't full yet. This change breaks no code since `grow()` is not `pub`.
2021-12-02Use `BTreeMap::from()` instead of using `BTreeMap::new()` with ↵Joseph T Lyons-4/+5
`BTreeMap::insert()`
2021-12-02Implement write() method for Box<MaybeUninit<T>>Martin Habovstiak-0/+36
This adds method similar to `MaybeUninit::write` main difference being it returns owned `Box`. This can be used to elide copy from stack safely, however it's not currently tested that the optimization actually occurs. Analogous methods are not provided for `Rc` and `Arc` as those need to handle the possibility of sharing. Some version of them may be added in the future. This was discussed in #63291 which this change extends.
2021-12-02Rollup merge of #91394 - Mark-Simulacrum:bump-stage0, r=pietroalbiniMatthias Krüger-1/+0
Bump stage0 compiler r? `@pietroalbini` (or anyone else)
2021-11-30Apply cfg-bootstrap switchMark Rousskov-1/+0
2021-11-30Auto merge of #91352 - nnethercote:RawVec-reserve_for_push, r=dtolnaybors-1/+9
Introduce `RawVec::reserve_for_push`. If `Vec::push`'s capacity check fails it calls `RawVec::reserve`, which then also does a capacity check. This commit introduces `reserve_for_push` which skips the redundant capacity check, for some slight compile time speed-ups. I tried lots of minor variations on this, e.g. different inlining attributes. This was the best one I could find. r? `@ghost`
2021-11-29Remove unnecessary check in VecDeque::growCédric Barreteau-9/+11
All callers already check that the buffer is full before calling `grow()`. This is where it makes the most sense, since `grow()` is `inline(never)` and we don't want to pay for a function call just for that check. It could also be argued that it would be correct to call `grow()` even if the buffer wasn't full yet. This change breaks no code since `grow()` is not `pub`.
2021-11-30Introduce `RawVec::reserve_for_push`.Nicholas Nethercote-1/+9
If `Vec::push`'s capacity check fails it calls `RawVec::reserve`, which then also does a capacity check. This commit introduces `reserve_for_push` which skips the redundant capacity check, for some slight compile time speed-ups. I tried lots of minor variations on this, e.g. different inlining attributes. This was the best one I could find.
2021-11-27Auto merge of #91241 - dtolnay:firstchunk, r=oli-obkbors-7/+5
Eliminate an unreachable codepath from String::from_utf8_lossy `Utf8Lossy`'s `Iterator` implementation ensures that only the **final** chunk has an empty slice for `broken`: https://github.com/rust-lang/rust/blob/dd549dcab404ec4c7d07b5a83aca5bdd7171138f/library/core/src/str/lossy.rs#L46-L47 Thus the only way the **first** chunk could have an empty `broken` is if it is the **final** chunk, i.e. there is only one chunk total. And the only way that there could be one chunk total with an empty `broken` is if the whole input is valid utf8 and non-empty. That condition has already been handled by an early return, so at the point that the first `REPLACEMENT` is being pushed, it's impossible for `first_broken` to be empty.
2021-11-26Add a unit test for zero-sized types in `RawVec`.Nicholas Nethercote-0/+84
Because there's some subtle behaviour specific to zero-sized types and it's currently not well tested.
2021-11-25Eliminate an unreachable codepath from String::from_utf8_lossyDavid Tolnay-7/+5
Utf8Lossy's Iterator implementation ensures that only the final chunk has an empty slice for broken. Thus the only way the first chunk could have an empty broken is if it is the final chunk, i.e. there is only one chunk total. And the only way that there could be one chunk total is if the whole input is valid utf8 and non-empty. That condition has already been handled by an early return, so at the point that the first REPLACEMENT is being pushed, it's impossible for first_broken to be empty.
2021-11-25Implement VecDeque::retain_mutGuillaume Gomez-3/+34
2021-11-20fix doc links for `downcast_unchecked`Ibraheem Ahmed-0/+6
2021-11-20Rollup merge of #89741 - sdroege:arc-rc-from-inner-unsafe, r=Mark-SimulacrumMatthias Krüger-32/+45
Mark `Arc::from_inner` / `Rc::from_inner` as unsafe While it's an internal function, it is easy to create invalid Arc/Rcs to a dangling pointer with it. Fixes https://github.com/rust-lang/rust/issues/89740
2021-11-20document why we're not directly passing drop_ptr to drop_in_placeThe8472-0/+4
2021-11-20replace vec::Drain drop loops with drop_in_placeThe8472-14/+37
2021-11-19Rollup merge of #90480 - r00ster91:remove, r=kennytmYuki Okushi-1/+4
Mention `Vec::remove` in `Vec::swap_remove`'s docs Thought this was a nice addition.
2021-11-17Rollup merge of #90772 - GuillaumeGomez:vec-retain-mut, r=joshtriplettMatthias Krüger-1/+29
Add Vec::retain_mut This is to continue the discussion started in #83218. Original comment was: > Take 2 of #34265, since I needed this today. The reason I think why we should add `retain_mut` is for coherency and for discoverability. For example we have `chunks` and `chunks_mut` or `get` and `get_mut` or `iter` and `iter_mut`, etc. When looking for mutable `retain`, I would expect `retain_mut` to exist. It took me a while to find out about `drain_filter`. So even if it provides an API close to `drain_filter`, just for the discoverability, I think it's worth it. cc ``````@m-ou-se`````` ``````@jonas-schievink`````` ``````@Mark-Simulacrum``````
2021-11-15Stabilize format_args_captureJosh Triplett-1/+1
Works as expected, and there are widespread reports of success with it, as well as interest in it.
2021-11-15Give examples of format args capture in the fmt module documentationJosh Triplett-0/+18
2021-11-14Auto merge of #88282 - Neutron3529:patch-4, r=Mark-Simulacrumbors-0/+8
Optimize BinaryHeap::extend from Vec This improves the performance of extending `BinaryHeap`s from vectors directly. Future work may involve extending this optimization to other, similar, cases where the length of the added elements is well-known, but this is not yet done in this PR.
2021-11-13Auto merge of #90542 - the8472:privatize-the-means-of-rawvec-production, ↵bors-58/+6
r=joshtriplett Make RawVec private to alloc RawVec was previously exposed for compiler-internal use (libarena specifically) in 1acbb0a9350560d951359cc359361b87992a6f2b Since it is unstable, doc-hidden and has no associated tracking issue it was never meant for public use. And since it is no longer used outside alloc itself it can be made private again. Also remove some functions that are dead due to lack of internal users.
2021-11-12add tracking issue for `downcast_unchecked`Ibraheem Ahmed-3/+3
2021-11-12add unchecked downcast methodsIbraheem Ahmed-28/+103
2021-11-12Add Vec::retain_mutGuillaume Gomez-1/+29
2021-11-12provide a `SpecExtend` trait for `Vec<T>`Neutron3529-0/+8
The discussion is [here](https://internals.rust-lang.org/t/append-vec-to-binaryheap/15209/3)