about summary refs log tree commit diff
path: root/library/alloc
AgeCommit message (Collapse)AuthorLines
2021-12-12Rollup merge of #91814 - japm48:spelling-fix, r=RalfJungMatthias Krüger-8/+8
doc: fix typo in comments `dereferencable -> dereferenceable` Fixes #91802.
2021-12-12Rollup merge of #91746 - ssomers:btree_tests, r=Mark-SimulacrumMatthias Krüger-6/+38
Btree: assert more API compatibility Introducing a member such as `BTreeSet::min()` would silently break compatibility if no code calls the existing `BTreeSet::min(set)`. `BTreeSet` is the only btree class silently bringing in stable members, apart from many occurrences of `#[derive(Debug)]` on iterators. r? `@Mark-Simulacrum`
2021-12-12doc: fix typo in commentsjapm48-8/+8
dereferencable -> dereferenceable
2021-12-11Fix zero-sized reference to deallocated memoryThe 8472-4/+6
fixes #91772
2021-12-11update feature gateTennyZhuang-4/+4
2021-12-11add BinaryHeap::try_reserve and BinaryHeap::try_reserve_exactTennyZhuang-0/+79
Signed-off-by: TennyZhuang <zty0826@gmail.com>
2021-12-11Auto merge of #91761 - matthiaskrgr:rollup-bjowmvz, r=matthiaskrgrbors-21/+20
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 #91755 - not-my-profile:fix-const_linked_list_new-since, ↵Matthias Krüger-1/+1
r=dtolnay Fix since attribute for const_linked_list_new feature https://github.com/rust-lang/rust/pull/63684 was merged for 1.39 not 1.32
2021-12-10Rollup merge of #91709 - juniorbassani:use-from-array-in-set-examples, r=jyn514Matthias Krüger-19/+18
Replace iterator-based set construction by *Set::From<[T; N]> This uses the array-based construction for `BtreeSet`s and `HashSet`s instead of first creating an iterator. I could also replace the `let mut a = Set::new(); a.insert(...);` fragments if desired.
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-04update vec::retain benchmarksThe 8472-2/+17
Add `into_iter().filter().collect()` as a comparison point since it was reported to be faster than `retain`. Remove clone inside benchmark loop to reduce allocator noise.
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-27Auto merge of #89916 - the8472:advance_by-avoid-err-0, r=dtolnaybors-0/+3
Fix Iterator::advance_by contract inconsistency The `advance_by(n)` docs state that in the error case `Err(k)` that k is always less than n. It also states that `advance_by(0)` may return `Err(0)` to indicate an exhausted iterator. These statements are inconsistent. Since only one implementation (Skip) actually made use of that I changed it to return Ok(()) in that case too. While adding some tests I also found a bug in `Take::advance_back_by`.
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