about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2021-02-25Convert primitives to use intra-doc linksJoshua Nelson-17/+20
2021-02-24library: Normalize safety-for-unsafe-block commentsMiguel Ojeda-10/+11
Almost all safety comments are of the form `// SAFETY:`, so normalize the rest and fix a few of them that should have been a `/// # Safety` section instead. Furthermore, make `tidy` only allow the uppercase form. While currently `tidy` only checks `core`, it is a good idea to prevent `core` from drifting to non-uppercase comments, so that later we can start checking `alloc` etc. too. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-02-23Rollup merge of #82113 - m-ou-se:panic-format-lint, r=estebankDylan DPC-0/+1
Improve non_fmt_panic lint. This change: - fixes the span used by this lint in the case the panic argument is a single macro expansion (e.g. `panic!(a!())`); - adds a suggestion for `panic!(format!(..))` to remove `format!()` instead of adding `"{}", ` or using `panic_any` like it does now; and - fixes the incorrect suggestion to replace `panic![123]` by `panic_any(123]`. Fixes #82109. Fixes #82110. Fixes #82111. Example output: ``` warning: panic message is not a string literal --> src/main.rs:8:12 | 8 | panic!(format!("error: {}", "oh no")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(non_fmt_panic)]` on by default = note: this is no longer accepted in Rust 2021 = note: the panic!() macro supports formatting, so there's no need for the format!() macro here help: remove the `format!(..)` macro call | 8 | panic!("error: {}", "oh no"); | -- -- ``` r? `@estebank`
2021-02-23BTree: fix untrue safetyStein Somers-16/+15
2021-02-23BTree: no longer define impossible castsStein Somers-8/+10
2021-02-23BTree: split off reusable components from range_searchStein Somers-118/+228
2021-02-23Auto merge of #82076 - jyn514:update-bootstrap, r=Mark-Simulacrumbors-5/+0
Update the bootstrap compiler This updates the bootstrap compiler, notably leaving out a change to enable semicolon in macro expressions lint, because stdarch still depends on the old behavior.
2021-02-23Add more links between hash and btree collectionsJoshua Nelson-3/+4
- Link from `core::hash` to `HashMap` and `HashSet` - Link from HashMap and HashSet to the module-level documentation on when to use the collection - Link from several collections to Wikipedia articles on the general concept
2021-02-23Auto merge of #82430 - Dylan-DPC:rollup-nu4kfyc, r=Dylan-DPCbors-7/+13
Rollup of 12 pull requests Successful merges: - #79423 (Enable smart punctuation) - #81154 (Improve design of `assert_len`) - #81235 (Improve suggestion for tuple struct pattern matching errors.) - #81769 (Suggest `return`ing tail expressions that match return type) - #81837 (Slight perf improvement on char::to_ascii_lowercase) - #81969 (Avoid `cfg_if` in `std::os`) - #81984 (Make WASI's `hard_link` behavior match other platforms.) - #82091 (use PlaceRef abstractions more consistently) - #82128 (add diagnostic items for OsString/PathBuf/Owned as well as to_vec on slice) - #82166 (add s390x-unknown-linux-musl target) - #82234 (Remove query parameters when skipping search results) - #82255 (Make `treat_err_as_bug` Option<NonZeroUsize>) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
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