about summary refs log tree commit diff
path: root/library/alloc/src/vec
AgeCommit message (Collapse)AuthorLines
2021-10-31Rollup merge of #89899 - jkugelman:must-use-alloc, r=joshtriplettMatthias Krüger-0/+1
Add #[must_use] to remaining alloc functions I've run out of compelling reasons to group functions together across crates so I'm just going to go module-by-module. This is everything remaining from the `alloc` crate. I ignored these because they might be used to purposefully leak memory... or other allocator shenanigans? I dunno. I'll add them if y'all tell me to. ```rust alloc::alloc unsafe fn alloc(layout: Layout) -> *mut u8; alloc::alloc unsafe fn alloc_zeroed(layout: Layout) -> *mut u8; alloc::sync::Arc<T> fn into_raw(this: Self) -> *const T; ``` I don't know why clippy ignored these. I added them myself: ```rust alloc::collections::btree_map::BTreeMap<K, V> fn range<T: ?Sized, R>(&self, range: R) -> Range<'_, K, V>; alloc::collections::btree_set::BTreeSet<T> fn range<K: ?Sized, R>(&self, range: R) -> Range<'_, T>; ``` I added these non-mutating `mut` functions: ```rust alloc::collections::btree_map::BTreeMap<K, V> fn range_mut<T: ?Sized, R>(&mut self, range: R) -> RangeMut<'_, K, V>; alloc::collections::btree_map::BTreeMap<K, V> fn iter_mut(&mut self) -> IterMut<'_, K, V>; alloc::collections::btree_map::BTreeMap<K, V> fn values_mut(&mut self) -> ValuesMut<'_, K, V>; alloc::collections::linked_list::LinkedList<T> fn iter_mut(&mut self) -> IterMut<'_, T>; alloc::collections::linked_list::LinkedList<T> fn cursor_front_mut(&mut self) -> CursorMut<'_, T>; alloc::collections::linked_list::LinkedList<T> fn cursor_back_mut(&mut self) -> CursorMut<'_, T>; alloc::collections::linked_list::LinkedList<T> fn front_mut(&mut self) -> Option<&mut T>; alloc::collections::linked_list::LinkedList<T> fn back_mut(&mut self) -> Option<&mut T>; alloc::collections::linked_list::CursorMut<'a, T> fn current(&mut self) -> Option<&mut T>; alloc::collections::linked_list::CursorMut<'a, T> fn peek_next(&mut self) -> Option<&mut T>; alloc::collections::linked_list::CursorMut<'a, T> fn peek_prev(&mut self) -> Option<&mut T>; alloc::collections::linked_list::CursorMut<'a, T> fn front_mut(&mut self) -> Option<&mut T>; alloc::collections::linked_list::CursorMut<'a, T> fn back_mut(&mut self) -> Option<&mut T>; ``` I moved a few existing `#[must_use]`s from functions onto the iterator types they return: `IntoIterSorted`, `IntoKeys`, `IntoValues`. Parent issue: #89692 r? `@joshtriplett`
2021-10-20Prevent invalid values from existing in Vec::swap_removeGiacomo Stevanato-3/+4
2021-10-15Auto merge of #89337 - mbrubeck:vec-leak, r=m-ou-sebors-3/+5
Avoid allocations and copying in Vec::leak The [`Vec::leak`] method (#62195) is currently implemented by calling `Vec::into_boxed_slice` and `Box::leak`. This shrinks the vector before leaking it, which potentially causes a reallocation and copies the vector's contents. By avoiding the conversion to `Box`, we can instead leak the vector without any expensive operations, just by returning a slice reference and forgetting the `Vec`. Users who *want* to shrink the vector first can still do so by calling `shrink_to_fit` explicitly. **Note:** This could break code that uses `Box::from_raw` to “un-leak” the slice returned by `Vec::leak`. However, the `Vec::leak` docs explicitly forbid this, so such code is already incorrect. [`Vec::leak`]: https://doc.rust-lang.org/stable/std/vec/struct.Vec.html#method.leak
2021-10-15Add #[must_use] to remaining alloc functionsJohn Kugelman-0/+1
2021-10-12Remove potentially unsound note on reconstructing a leaked Vec.Mara Bos-3/+0
2021-10-12Rollup merge of #89778 - jkugelman:must-use-as_type-conversions, r=joshtriplettthe8472-0/+1
Add #[must_use] to as_type conversions Clippy missed these: ```rust alloc::string::String fn as_mut_str(&mut self) -> &mut str; core::mem::NonNull<T> unsafe fn as_uninit_mut<'a>(&mut self) -> &'a MaybeUninit<T>; str unsafe fn as_bytes_mut(&mut self) -> &mut [u8]; str fn as_mut_ptr(&mut self) -> *mut u8; ``` Parent issue: #89692 r? ````@joshtriplett````
2021-10-12Mention Rust version in Vec::leak docs.Mara Bos-4/+5
2021-10-11Add #[must_use] to as_type conversionsJohn Kugelman-0/+1
2021-10-10Add #[must_use] to alloc constructorsJohn Kugelman-0/+2
2021-10-04Rollup merge of #89413 - matthewjasper:spec-marker-fix, r=nikomatsakisJubilee-16/+13
Correctly handle supertraits for min_specialization Supertraits of specialization markers could circumvent checks for min_specialization. Elaborating predicates prevents this. r? ````@nikomatsakis````
2021-10-04Rollup merge of #87993 - kornelski:try_reserve_stable, r=joshtriplettJubilee-4/+2
Stabilize try_reserve Stabilization PR for the [`try_reserve` feature](https://github.com/rust-lang/rust/issues/48043#issuecomment-898040475).
2021-10-04Rollup merge of #87091 - the8472:more-advance-by-impls, r=joshtriplettJubilee-0/+46
implement advance_(back_)_by on more iterators Add more efficient, non-default implementations for `feature(iter_advance_by)` (#77404) on more iterators and adapters. This PR only contains implementations where skipping over items doesn't elide any observable side-effects such as user-provided closures or `clone()` functions. I'll put those in a separate PR.
2021-10-04Stabilize try_reserveKornel-4/+2
2021-10-03Rollup merge of #89401 - owengage:master, r=joshtriplettManish Goregaokar-0/+1
Add truncate note to Vec::resize A very minor addition to the `Vec::resize` documentation to point out the `truncate` method. When I was searching for something matching `truncate` I managed to miss it, along with some colleagues. We later found it by chance. We did find `resize` however, so I was hoping to point it out in the documentation.
2021-10-03Rollup merge of #88370 - Seppel3210:master, r=dtolnayManish Goregaokar-1/+6
Add missing `# Panics` section to `Vec` method namely `Vec::extend_from_within`
2021-10-03Auto merge of #88060 - TennyZhuang:optimize-vec-retain, r=dtolnaybors-3/+24
Optimize unnecessary check in Vec::retain The function `vec::Vec::retain` only have two stages: 1. Nothing was deleted. 2. Some elements were deleted. Here is an unnecessary check `if g.deleted_cnt > 0` in the loop, and it's difficult for compiler to optimize it. I split the loop into two stages manully and keep the code clean using const generics. I write a special but common bench case for this optimization. I call retain on vec but keep all elements. Before and after this optimization: ``` test vec::bench_retain_whole_100000 ... bench: 84,803 ns/iter (+/- 17,314) ``` ``` test vec::bench_retain_whole_100000 ... bench: 42,638 ns/iter (+/- 16,910) ``` The result is expected, there are two `if`s before the optimization and one `if` after.
2021-10-02Make diangostic item names consistentCameron Steffen-1/+1
2021-10-01Clarify a sentence in the documentation of Vec (#84488)chrismit3s-1/+1
2021-09-30Fix standard library for min_specialization changesMatthew Jasper-16/+13
2021-09-30fix issues pointed out in reviewThe8472-10/+11
2021-09-30implement advance_(back_)_by on more iteratorsThe8472-0/+45
2021-09-30Add truncate note to Vec::resizeOwen Gage-0/+1
2021-09-28Additional docs about Vec::leak behaviorMatt Brubeck-2/+5
2021-09-28Avoid allocations and copying in Vec::leakMatt Brubeck-1/+2
Don't shrink the Vec (by calling into_boxed_slice) before leaking it.
2021-09-26Auto merge of #89144 - sexxi-goose:insig_stdlib, r=nikomatsakisbors-0/+2
2229: Mark insignificant dtor in stdlib I looked at all public [stdlib Drop implementations](https://doc.rust-lang.org/stable/std/ops/trait.Drop.html#implementors) and categorized them into Insigificant/Maybe/Significant Drop. Reasons are noted here: https://docs.google.com/spreadsheets/d/19edb9r5lo2UqMrCOVjV0fwcSdS-R7qvKNL76q7tO8VA/edit#gid=1838773501 One thing missing from this PR is tagging HashMap as insigificant destructor as that needs some discussion. r? `@Mark-Simulacrum` cc `@nikomatsakis`
2021-09-25Rollup merge of #89216 - r00ster91:bigo, r=dtolnayManish Goregaokar-3/+3
Consistent big O notation This makes the big O time complexity notation in places with markdown support more consistent. Inspired by #89210
2021-09-25Auto merge of #88343 - steffahn:fix_code_spacing, r=jyn514bors-7/+9
Fix spacing of links in inline code. Similar to #80733, but the focus is different. This PR eliminates all occurrences of pieced-together inline code blocks like [`Box`]`<`[`Option`]`<T>>` and replaces them with good-looking ones (using HTML-syntax), like <code>[Box]<[Option]\<T>></code>. As far as I can tell, I should’ve found all of these in the standard library (regex search with `` r"`\]`|`\[`" ``) \[except for in `core::convert` where I’ve noticed other things in the docs that I want to fix in a separate PR]. In particular, unlike #80733, I’ve added almost no new instance of inline code that’s broken up into multiple links (or some link and some link-free part). I also added tooltips (the stuff in quotes for the markdown link listings) in places that caught my eye, but that’s by no means systematic, just opportunistic. [Box]: https://doc.rust-lang.org/std/boxed/struct.Box.html "Box" [`Box`]: https://doc.rust-lang.org/std/boxed/struct.Box.html "Box" [Option]: https://doc.rust-lang.org/std/option/enum.Option.html "Option" [`Option`]: https://doc.rust-lang.org/std/option/enum.Option.html "Option" Context: I got annoyed by repeatedly running into new misformatted inline code while reading the standard library docs. I know that once issue #83997 (and/or related ones) are resolved, these changes become somewhat obsolete, but I fail to notice much progress on that end right now. r? `@jyn514`
2021-09-25Apply 16 commits (squashed)Frank Steffahn-7/+9
---------- Fix spacing for links inside code blocks, and improve link tooltips in alloc::fmt ---------- Fix spacing for links inside code blocks, and improve link tooltips in alloc::{rc, sync} ---------- Fix spacing for links inside code blocks, and improve link tooltips in alloc::string ---------- Fix spacing for links inside code blocks in alloc::vec ---------- Fix spacing for links inside code blocks in core::option ---------- Fix spacing for links inside code blocks, and improve a few link tooltips in core::result ---------- Fix spacing for links inside code blocks in core::{iter::{self, iterator}, stream::stream, poll} ---------- Fix spacing for links inside code blocks, and improve a few link tooltips in std::{fs, path} ---------- Fix spacing for links inside code blocks in std::{collections, time} ---------- Fix spacing for links inside code blocks in and make formatting of `&str`-like types consistent in std::ffi::{c_str, os_str} ---------- Fix spacing for links inside code blocks, and improve link tooltips in std::ffi ---------- Fix spacing for links inside code blocks, and improve a few link tooltips in std::{io::{self, buffered::{bufreader, bufwriter}, cursor, util}, net::{self, addr}} ---------- Fix typo in link to `into` for `OsString` docs ---------- Remove tooltips that will probably become redundant in the future ---------- Apply suggestions from code review Replacing `…std/primitive.reference.html` paths with just `reference` Co-authored-by: Joshua Nelson <github@jyn.dev> ---------- Also replace `…std/primitive.reference.html` paths with just `reference` in `core::pin`
2021-09-24consistent big O notationr00ster91-3/+3
2021-09-22PR fixupAman Arora-2/+2
2021-09-212229: Annotate stdlib with insignficant dtorsAman Arora-0/+2
2021-09-17Fix missing `no_global_oom_handling` cfg-gatingGary Guo-0/+1
2021-09-17Optimize unnecessary check in Vec::retainTennyZhuang-3/+24
Co-authored-by: oxalica <oxalicc@pm.me>
2021-08-26Add missing # Panics section to `Vec` methodSebastian Widua-1/+6
namely `Vec::extend_from_within`
2021-08-17Constified `Default` implementationsDeadbeef-1/+2
The libs-api team agrees to allow const_trait_impl to appear in the standard library as long as stable code cannot be broken (they are properly gated) this means if the compiler teams thinks it's okay, then it's okay. My priority on constifying would be: 1. Non-generic impls (e.g. Default) or generic impls with no bounds 2. Generic functions with bounds (that use const impls) 3. Generic impls with bounds 4. Impls for traits with associated types For people opening constification PRs: please cc me and/or oli-obk.
2021-08-12Add missing cfg attributeBenoît du Garreau-0/+3
2021-08-10Specialize `Vec::clone_from` for `Copy` typesBenoît du Garreau-10/+27
This should improve performance and reduce code size. This also improves `clone_from` for `String`, `OsString` and `PathBuf`.
2021-08-08Auto merge of #86879 - YohDeadfall:stabilize-vec-shrink-to, r=dtolnaybors-2/+1
Stabilize Vec<T>::shrink_to This PR stabilizes `shrink_to` feature and closes the corresponding issue. The second point was addressed already, and no `panic!` should occur. Closes #56431.
2021-08-08Bump shrink_to stabilization to Rust 1.56David Tolnay-1/+1
2021-08-05alloc: Use intra doc links for the reserve functionest31-2/+6
The sentence exists to highlight the existence of a performance footgun of repeated calls of the reserve_exact function.
2021-08-02Rollup merge of #87644 - Flying-Toast:vec-remove-note, r=the8472Yuki Okushi-0/+6
Recommend `swap_remove` in `Vec::remove` docs I was able to increase the performance (by 20%!) of my project by changing a `Vec::remove` call to `Vec::swap_remove` in a hot function. I think we should explicitly put a note in the Vec::remove docs to guide people in the right direction so they don't make a similar oversight.
2021-07-31Auto merge of #87488 - kornelski:track-remove, r=dtolnaybors-0/+2
Track caller of Vec::remove() `vec.remove(invalid)` doesn't print a helpful source position: > thread 'main' panicked at 'removal index (is 99) should be < len (is 1)', **library/alloc/src/vec/mod.rs:1379:13**
2021-07-30Recommend `swap_remove` in `Vec::remove` docsFlying-Toast-0/+6
2021-07-29Fix may not to appropriate might not or must notAli Malik-2/+2
2021-07-28Documentation improvementsFrank Steffahn-2/+17
2021-07-28Make `SpecInPlaceCollect` use `TrustedRandomAccessNoCoerce`Frank Steffahn-2/+4
2021-07-28Remove redundant bounds on get_unchecked for vec_deque iterators, and run fmtFrank Steffahn-1/+3
2021-07-28Add back TrustedRandomAccess-specialization for Vec, but only without coercionsFrank Steffahn-1/+33
2021-07-28Remove unsound TrustedRandomAccess implementationsFrank Steffahn-30/+1
Removes the implementations that depend on the user-definable trait `Copy`.
2021-07-26Track caller of Vec::remove()Kornel-0/+2