about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2021-02-23Rollup merge of #82128 - anall:feature/add_diagnostic_items, r=davidtwcoDylan DPC-0/+3
add diagnostic items for OsString/PathBuf/Owned as well as to_vec on slice This is adding diagnostic items to be used by rust-lang/rust-clippy#6730, but my understanding is the clippy-side change does need to be done over there since I am adding a new clippy feature. Add diagnostic items to the following types: OsString (os_string_type) PathBuf (path_buf_type) Owned (to_owned_trait) As well as the to_vec method on slice/[T]
2021-02-23Rollup merge of #81154 - dylni:improve-design-of-assert-len, r=KodrAusDylan DPC-7/+10
Improve design of `assert_len` It was discussed in the [tracking issue](https://github.com/rust-lang/rust/issues/76393#issuecomment-761765448) that `assert_len`'s name and usage are confusing. This PR improves them based on a suggestion by ``@scottmcm`` in that issue. I also improved the documentation to make it clearer when you might want to use this method. Old example: ```rust let range = range.assert_len(slice.len()); ``` New example: ```rust let range = range.ensure_subset_of(..slice.len()); ``` Fixes #81157
2021-02-23Auto merge of #81937 - ssomers:btree_drainy_refactor_9b, r=Mark-Simulacrumbors-98/+67
BTree: move more shared iterator code into navigate.rs The functions in navigate.rs only exist to support iterators, and these look easier on my eyes if there is a shared `struct` with the recurring pair of handles. r? `@Mark-Simulacrum`
2021-02-22Auto merge of #81362 - ssomers:btree_drainy_refactor_8, r=Mark-Simulacrumbors-146/+176
BTreeMap: gather and decompose reusable tree fixing functions This is kind of pushing it as a standalone refactor, probably only useful for #81075 (or similar). r? `@Mark-Simulacrum`
2021-02-21BTreeMap: correct tests for alternative choices of BStein Somers-5/+6
2021-02-21Improve sift_down performance in BinaryHeapHan Mertens-2/+2
Because child > 0, the two statements are equivalent, but using saturating_sub and <= yields in faster code. This is most notable in the binary_heap::bench_into_sorted_vec benchmark, which shows a speedup of 1.26x, which uses sift_down_range internally. The speedup of pop (that uses sift_down_to_bottom internally) is much less significant as the sifting method is not called in a loop.
2021-02-21Rollup merge of #81706 - SkiFire13:document-binaryheap-unsafe, r=Mark-SimulacrumYuki Okushi-49/+117
Document BinaryHeap unsafe functions `BinaryHeap` contains some private safe functions but that are actually unsafe to call. This PR marks them `unsafe` and documents all the `unsafe` function calls inside them. While doing this I might also have found a bug: some "SAFETY" comments in `sift_down_range` and `sift_down_to_bottom` are valid only if you assume that `child` doesn't overflow. However it may overflow if `end > isize::MAX` which can be true for ZSTs (but I think only for them). I guess the easiest fix would be to skip any sifting if `mem::size_of::<T> == 0`. Probably conflicts with #81127 but solving the eventual merge conflict should be pretty easy.
2021-02-21Rollup merge of #81300 - ssomers:btree_cleanup_leak_tests, r=Mark-SimulacrumYuki Okushi-217/+337
BTree: share panicky test code & test panic during clear, clone Bases almost all tests of panic on the same, richer definition, and extends it to cloning to test panic during clone. r? ```@Mark-Simulacrum```
2021-02-20Update the bootstrap compilerJoshua Nelson-5/+0
Note this does not change `core::derive` since it was merged after the beta bump.
2021-02-20Add FIXME for safety comments that are invalid when T is a ZSTGiacomo Stevanato-0/+4
2021-02-20Document BinaryHeap unsafe functionsGiacomo Stevanato-49/+113
2021-02-20alloc: Added `as_slice` method to `BinaryHeap` collectionVlad Frolov-0/+23
2021-02-18Stabilize `unsafe_op_in_unsafe_fn` lintLeSeulArtichaut-1/+1
2021-02-17Vec::dedup optimization - panic gracefullySoveu-16/+65
2021-02-16Vec::dedup optimizationSoveu-6/+44
2021-02-16a few more diagnostic itemsAndrea Nall-1/+2
2021-02-15requested/proposed changesAndrea Nall-2/+2
2021-02-15Turn may_have_side_effect into an associated constantTomasz Miąsko-3/+1
The `may_have_side_effect` is an implementation detail of `TrustedRandomAccess` trait. It describes if obtaining an iterator element may have side effects. It is currently implemented as an associated function. Turn `may_have_side_effect` into an associated constant. This makes the value immediately available to the optimizer.
2021-02-15Rollup merge of #82060 - taiki-e:typo, r=m-ou-seJonas Schievink-12/+12
Fix typos in BTreeSet::{first, last} docs map -> set
2021-02-15BTree: move more shared iterator code into navigate.rsStein Somers-98/+67
2021-02-15add diagnostic itemsAndrea Nall-0/+2
Add diagnostic items to the following types: OsString (os_string_type) PathBuf (path_buf_type) Owned (to_owned_trait) As well as the to_vec method on slice/[T]
2021-02-14Only define rustc_diagnostic_item format_macro in not(test).Mara Bos-1/+1
2021-02-14Improve suggestion for panic!(format!(..)).Mara Bos-0/+1
2021-02-14Rollup merge of #81919 - ssomers:btree_cleanup_comments, r=Mark-SimulacrumDylan DPC-4/+5
BTreeMap: fix internal comments Salvaged from #81372 r? `@Mark-Simulacrum`
2021-02-14Auto merge of #81956 - ssomers:btree_post_75200, r=Mark-Simulacrumbors-19/+7
BTree: remove outdated traces of coercions The introduction of `marker::ValMut` (#75200) meant iterators no longer see mutable keys but their code still pretends it does. And settle on the majority style `Some(unsafe {…})` over `unsafe { Some(…) }`. r? `@Mark-Simulacrum`
2021-02-13Auto merge of #81494 - cuviper:btree-node-init, r=Mark-Simulacrumbors-18/+30
Initialize BTree nodes directly in the heap We can avoid any stack-local nodes entirely by using `Box::new_uninit`, and since the nodes are mostly `MaybeUninit` fields, we only need a couple of actual writes before `assume_init`. This should help with the stack overflows in #81444, and may also improve performance in general. r? `@Mark-Simulacrum` cc `@ssomers`
2021-02-13Fix typos in BTreeSet::{first, last} docsTaiki Endo-12/+12
2021-02-13Rollup merge of #82041 - notriddle:shared-from-slice-docs, r=m-ou-seYuki Okushi-0/+98
Add docs for shared_from_slice From impls The advantage of making these docs is mostly in pointing out that these functions all make new allocations and copy/clone/move the source into them. These docs are on the function, and not the `impl` block, to avoid showing the "[+] show undocumented items" button. CC #51430
2021-02-13Rollup merge of #81811 - schteve:fix_vec_retain_doc_test, r=m-ou-seYuki Okushi-3/+4
Fix doc test for Vec::retain(), now passes clippy::eval_order_dependence Doc test for Vec::retain() works correctly but is flagged by clippy::eval_order_dependence. Fix avoids the issue by using an iterator instead of an index.
2021-02-12Update new usage of `assert_len`dylni-2/+2
2021-02-12Rename `Range::ensure_subset_of` to `slice::range`dylni-5/+8
2021-02-12Fix possible soundness issue in `ensure_subset_of`dylni-4/+4
2021-02-12Improve design of `assert_len`dylni-5/+5
2021-02-12Rollup merge of #82023 - MikailBag:boxed-docs-unallow, r=jyn514Dylan DPC-2/+0
Remove unnecessary lint allow attrs on example It seems they are not needed anymore.
2021-02-12Add docs for shared_from_slice From implsMichael Howell-0/+98
The advantage of making these docs is mostly in pointing out that these functions all make new allocations and copy/clone/move the source into them. These docs are on the function, and not the `impl` block, to avoid showing the "[+] show undocumented items" button. CC #51430
2021-02-12Use raw ref macros as in #80886Stein Somers-3/+3
2021-02-12Initialize BTree nodes directly in the heapJosh Stone-18/+30
2021-02-12Remove unnecessary lint allow attrs on exampleMikail Bagishov-2/+0
2021-02-12Auto merge of #81486 - ssomers:btree_separate_drop, r=Mark-Simulacrumbors-65/+106
BTreeMap: disentangle Drop implementation from IntoIter No longer require every `BTreeMap` to dig up its last leaf edge before dying. This speeds up the `clone_` benchmarks by 25% for normal keys and values (far less for huge values). r? `@Mark-Simulacrum`
2021-02-11Auto merge of #81126 - oxalica:retain-early-drop, r=m-ou-sebors-11/+64
Optimize Vec::retain Use `copy_non_overlapping` instead of `swap` to reduce memory writes, like what we've done in #44355 and `String::retain`. #48065 already tried to do this optimization but it is reverted in #67300 due to bad codegen of `DrainFilter::drop`. This PR re-implement the drop-then-move approach. I did a [benchmark](https://gist.github.com/oxalica/3360eec9376f22533fcecff02798b698) on small-no-drop, small-need-drop, large-no-drop elements with different predicate functions. It turns out that the new implementation is >20% faster in average for almost all cases. Only 2/24 cases are slower by 3% and 5%. See the link above for more detail. I think regression in may-panic cases is due to drop-guard preventing some optimization. If it's permitted to leak elements when predicate function of element's `drop` panic, the new implementation should be almost always faster than current one. I'm not sure if we should leak on panic, since there is indeed an issue (#52267) complains about it before.
2021-02-10BTree: remove outdated traces of coercionsStein Somers-19/+7
2021-02-10Rollup merge of #81687 - WaffleLapkin:split_at_spare, r=KodrAusYuki Okushi-1/+53
Make Vec::split_at_spare_mut public This PR introduces a new method to the public API, under `vec_split_at_spare` feature gate: ```rust impl<T, A: Allocator> impl Vec<T, A> { pub fn split_at_spare_mut(&mut self) -> (&mut [T], &mut [MaybeUninit<T>]); } ``` The method returns 2 slices, one slice references the content of the vector, and the other references the remaining spare capacity. The method was previously implemented while adding `Vec::extend_from_within` in #79015, and used to implement `Vec::spare_capacity_mut` (as the later is just a subset of former one). See also previous [discussion in `Vec::spare_capacity_mut` tracking issue](https://github.com/rust-lang/rust/issues/75017#issuecomment-770381335). ## Unresolved questions - [ ] Should we consider changing the name? `split_at_spare_mut` doesn't seem like an intuitive name - [ ] Should we deprecate `Vec::spare_capacity_mut`? Any usecase of `Vec::spare_capacity_mut` can be replaced with `Vec::split_at_spare_mut` (but not vise-versa) r? `@KodrAus`
2021-02-10Rollup merge of #80438 - crlf0710:box_into_inner, r=m-ou-seYuki Okushi-0/+17
Add `Box::into_inner`. This adds a `Box::into_inner` method to the `Box` type. <del>I actually suggest deprecating the compiler magic of `*b` if this gets stablized in the future.</del> r? `@m-ou-se`
2021-02-10update tracking issue for vec_split_at_spareAshley Mannix-1/+1
2021-02-09BTreeMap: disentangle Drop implementation from IntoIterStein Somers-65/+106
2021-02-09BTreeMap: gather and decompose reusable tree fixing functionsStein Somers-146/+176
2021-02-09BTreeMap: fix internal commentsStein Somers-4/+5
2021-02-09BTreeMap: share panicky test code & test panic during clear, cloneStein Somers-183/+303
2021-02-09BTreeMap/BTreeSet: separate off code supporting testsStein Somers-34/+34
2021-02-09Auto merge of #81905 - Dylan-DPC:rollup-mxpz1j7, r=Dylan-DPCbors-2/+12
Rollup of 11 pull requests Successful merges: - #72209 (Add checking for no_mangle to unsafe_code lint) - #80732 (Allow Trait inheritance with cycles on associated types take 2) - #81697 (Add "every" as a doc alias for "all".) - #81826 (Prefer match over combinators to make some Box methods inlineable) - #81834 (Resolve typedef in HashMap lldb pretty-printer only if possible) - #81841 ([rustbuild] Output rustdoc-json-types docs ) - #81849 (Expand the docs for ops::ControlFlow a bit) - #81876 (parser: Fix panic in 'const impl' recovery) - #81882 (:arrow_up: rust-analyzer) - #81888 (Fix pretty printer macro_rules with semicolon.) - #81896 (Remove outdated comment in windows' mutex.rs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup