about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2021-02-06Rollup merge of #81434 - ssomers:btree_drain_filter_doc_update, r=dtolnayJonas Schievink-16/+18
BTree: fix documentation of unstable public members As rightfully requested in #62924 & #70530. r? `@Mark-Simulacrum`
2021-02-06Prefer match intead of combinators to make some Box function inlineableLzu Tao-2/+12
2021-02-06BTreeMap: remove Ord bound where it is absent elsewhereStein Somers-20/+22
2021-02-06BTreeMap: fix documentation of unstable public membersStein Somers-16/+18
2021-02-06Rollup merge of #81610 - ssomers:btree_emphasize_ord_bound, r=dtolnayMara Bos-54/+191
BTreeMap: make Ord bound explicit, compile-test its absence Most `BTreeMap` and `BTreeSet` members are subject to an `Ord` bound but a fair number of methods are not. To better convey and perhaps later tune the `Ord` bound, make it stand out in individual `where` clauses, instead of once far away at the beginning of an `impl` block. This PR does not introduce or remove any bounds. Also adds compilation test cases checking that the bound doesn't creep in unintended on the historically unbounded methods.
2021-02-04Revert "Avoid leaking block expression values"Felix S. Klock II-1/+1
This reverts commit 4fef39113a514bb270f5661a82fdba17d3e41dbb.
2021-02-04Rollup merge of #81727 - m-ou-se:unstabilize-bits, r=Mark-SimulacrumMara Bos-0/+1
Revert stabilizing integer::BITS. We agreed in the libs meeting just now to revert stablization, since the [breakage](https://github.com/rust-lang/rust/issues/81654) is significant throughout the ecosystem, through `lexical-core`. cc https://github.com/rust-lang/rust/issues/76904 Fixes https://github.com/rust-lang/rust/issues/81654
2021-02-03Fixes #80335Yechan Bae-18/+24
2021-02-03Revert stabilizing integer::BITS.Mara Bos-0/+1
2021-02-03Stabilize the Wake traitYoshua Wuyts-7/+59
Co-Authored-By: Ashley Mannix <kodraus@hey.com>
2021-02-03Add note to `Vec::split_at_spare_mut` docs that the method is low-levelWaffle-0/+15
2021-02-03fix typo in library/alloc/src/vec/mod.rsWaffle Lapkin-1/+1
Co-authored-by: the8472 <the8472@users.noreply.github.com>
2021-02-03Make Vec::split_at_spare_mut publicWaffle-1/+38
This commit 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`, and used to implement `Vec::spare_capacity_mut` (as the later is just a subset of former one).
2021-02-02Rollup merge of #81588 - xfix:delete-doc-alias, r=Mark-SimulacrumJack Huey-0/+2
Add doc aliases for "delete" This patch adds doc aliases for "delete". The added aliases are supposed to reference usages `delete` in other programming languages. - `HashMap::remove`, `BTreeMap::remove` -> `Map#delete` and `delete` keyword in JavaScript. - `HashSet::remove`, `BTreeSet::remove` -> `Set#delete` in JavaScript. - `mem::drop` -> `delete` keyword in C++. - `fs::remove_file`, `fs::remove_dir`, `fs::remove_dir_all`-> `File#delete` in Java, `File#delete` and `Dir#delete` in Ruby. Before this change, searching for "delete" in documentation returned no results.
2021-02-02BTreeMap: make Ord bound explicit, compile-test its absenceStein Somers-54/+191
2021-02-02Auto merge of #79015 - WaffleLapkin:vec_append_from_within, r=KodrAusbors-4/+110
add `Vec::extend_from_within` method under `vec_extend_from_within` feature gate Implement <https://github.com/rust-lang/rfcs/pull/2714> ### tl;dr This PR adds a `extend_from_within` method to `Vec` which allows copying elements from a range to the end: ```rust #![feature(vec_extend_from_within)] let mut vec = vec![0, 1, 2, 3, 4]; vec.extend_from_within(2..); assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4]); vec.extend_from_within(..2); assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4, 0, 1]); vec.extend_from_within(4..8); assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4, 0, 1, 4, 2, 3, 4]); ``` ### Implementation notes Originally I've copied `@Shnatsel's` [implementation](https://github.com/WanzenBug/rle-decode-helper/blob/690742a0de158d391b7bde1a0c71cccfdad33ab3/src/lib.rs#L74) with some minor changes to support other ranges: ```rust pub fn append_from_within<R>(&mut self, src: R) where T: Copy, R: RangeBounds<usize>, { let len = self.len(); let Range { start, end } = src.assert_len(len);; let count = end - start; self.reserve(count); unsafe { // This is safe because `reserve()` above succeeded, // so `self.len() + count` did not overflow usize ptr::copy_nonoverlapping( self.get_unchecked(src.start), self.as_mut_ptr().add(len), count, ); self.set_len(len + count); } } ``` But then I've realized that this duplicates most of the code from (private) `Vec::append_elements`, so I've used it instead. Then I've applied `@KodrAus` suggestions from https://github.com/rust-lang/rust/pull/79015#issuecomment-727200852.
2021-02-02update tracking issue for vec_extend_from_withinAshley Mannix-1/+1
2021-01-31add `Vec::extend_from_within` methodWaffle-4/+110
Implement <https://github.com/rust-lang/rfcs/pull/2714>, changes from the RFC: - Rename the method `append_from_within` => `extend_from_within` - Loose :Copy bound => :Clone - Specialize in case of :Copy This commit also adds `Vec::split_at_spare` private method and use it to implement `Vec::spare_capacity_mut` and `Vec::extend_from_within`. This method returns 2 slices - initialized elements (same as `&mut vec[..]`) and uninitialized but allocated space (same as `vec.spare_capacity_mut()`).
2021-01-31Rollup merge of #81590 - KodrAus:stabilize/int_bits_const, r=m-ou-seJonas Schievink-1/+0
Stabilize int_bits_const Closes #76904 The FCP to stabilize the `int_bits_const` feature completed on the tracking issue.
2021-01-31Rollup merge of #81589 - Seppel3210:master, r=jonas-schievinkJonas Schievink-1/+1
Fix small typo in string.rs
2021-01-31Rollup merge of #80404 - JulianKnodt:arr_ref, r=oli-obkJonas Schievink-1/+0
Remove const_in_array_repeat Fixes #80371. Fixes #81315. Fixes #80767. Fixes #75682. I thought there might be some issue with `Repeats(_, 0)`, but if you increase the items in the array it still ICEs. I'm not sure if this is the best fix but it does fix the given issue.
2021-01-31stabilize int_bits_constAshley Mannix-1/+0
2021-01-31Fix small typoSebastian Widua-1/+1
2021-01-31Add doc aliases for "delete"Konrad Borowski-0/+2
This patch adds doc aliases for "delete". The added aliases are supposed to reference usages `delete` in other programming languages. - `HashMap::remove`, `BTreeMap::remove` -> `Map#delete` and `delete` keyword in JavaScript. - `HashSet::remove`, `BTreeSet::remove` -> `Set#delete` in JavaScript. - `mem::drop` -> `delete` keyword in C++. - `fs::remove_file`, `fs::remove_dir`, `fs::remove_dir_all` -> `File#delete` in Java, `File#delete` and `Dir#delete` in Ruby. Before this change, searching for "delete" in documentation returned no results.
2021-01-31Rollup merge of #80945 - sdroege:downcast-send-sync, r=m-ou-seJonas Schievink-0/+33
Add Box::downcast() for dyn Any + Send + Sync Looks like a plain omission, but unfortunately I just needed that in my code :)
2021-01-31Rollup merge of #80470 - SimonSapin:array-intoiter-type, r=m-ou-seJonas Schievink-1/+0
Stabilize by-value `[T; N]` iterator `core::array::IntoIter` Tracking issue: https://github.com/rust-lang/rust/issues/65798 This is unblocked now that `min_const_generics` has been stabilized in https://github.com/rust-lang/rust/pull/79135. This PR does *not* include the corresponding `IntoIterator` impl, which is https://github.com/rust-lang/rust/pull/65819. Instead, an iterator can be constructed through the `new` method. `new` would become unnecessary when `IntoIterator` is implemented and might be deprecated then, although it will stay stable.
2021-01-31Rollup merge of #79285 - yoshuawuyts:stabilize-arc_mutate_strong_count, ↵Jonas Schievink-13/+9
r=m-ou-se Stabilize Arc::{increment,decrement}_strong_count Tracking issue: https://github.com/rust-lang/rust/issues/71983 Stabilizes `Arc::{incr,decr}_strong_count`, enabling unsafely incrementing an decrementing the Arc strong count directly with fewer gotchas. This API was first introduced on nightly six months ago, and has not seen any changes since. The initial PR showed two existing pieces of code that would benefit from this API, and included a change inside the stdlib to use this. Given the small surface area, predictable use, and no changes since introduction, I'd like to propose we stabilize this. closes https://github.com/rust-lang/rust/issues/71983 r? `@Mark-Simulacrum` ## Links * [Initial implementation](https://github.com/rust-lang/rust/pull/70733) * [Motivation from #68700](https://github.com/rust-lang/rust/pull/68700#discussion_r396169064) * [Real world example in an executor](https://docs.rs/extreme/666.666.666666/src/extreme/lib.rs.html#13)
2021-01-30Remove const_in_array_rep_exprkadmin-1/+0
2021-01-30Bump stable version of arc_mutate_strong_countMara Bos-2/+2
2021-01-30Rollup merge of #81499 - SOF3:patch-1, r=sanxiynYuki Okushi-1/+1
Updated Vec::splice documentation Replacing with equal number of values does not increase the length of the vec. Reference: https://stackoverflow.com/a/62559271/3990767
2021-01-30Rollup merge of #80886 - RalfJung:stable-raw-ref-macros, r=m-ou-seYuki Okushi-9/+8
Stabilize raw ref macros This stabilizes `raw_ref_macros` (https://github.com/rust-lang/rust/issues/73394), which is possible now that https://github.com/rust-lang/rust/issues/74355 is fixed. However, as I already said in https://github.com/rust-lang/rust/issues/73394#issuecomment-751342185, I am not particularly happy with the current names of the macros. So I propose we also change them, which means I am proposing to stabilize the following in `core::ptr`: ```rust pub macro const_addr_of($e:expr) { &raw const $e } pub macro mut_addr_of($e:expr) { &raw mut $e } ``` The macro name change means we need another round of FCP. Cc `````@rust-lang/libs````` Fixes #73394
2021-01-30Rollup merge of #79023 - yoshuawuyts:stream, r=KodrAusYuki Okushi-0/+15
Add `core::stream::Stream` [[Tracking issue: #79024](https://github.com/rust-lang/rust/issues/79024)] This patch adds the `core::stream` submodule and implements `core::stream::Stream` in accordance with [RFC2996](https://github.com/rust-lang/rfcs/pull/2996). The RFC hasn't been merged yet, but as requested by the libs team in https://github.com/rust-lang/rfcs/pull/2996#issuecomment-725696389 I'm filing this PR to get the ball rolling. ## Documentatation The docs in this PR have been adapted from [`std::iter`](https://doc.rust-lang.org/std/iter/index.html), [`async_std::stream`](https://docs.rs/async-std/1.7.0/async_std/stream/index.html), and [`futures::stream::Stream`](https://docs.rs/futures/0.3.8/futures/stream/trait.Stream.html). Once this PR lands my plan is to follow this up with PRs to add helper methods such as `stream::repeat` which can be used to document more of the concepts that are currently missing. That will allow us to cover concepts such as "infinite streams" and "laziness" in more depth. ## Feature gate The feature gate for `Stream` is `stream_trait`. This matches the `#[lang = "future_trait"]` attribute name. The intention is that only the APIs defined in RFC2996 will use this feature gate, with future additions such as `stream::repeat` using their own feature gates. This is so we can ensure a smooth path towards stabilizing the `Stream` trait without needing to stabilize all the APIs in `core::stream` at once. But also don't start expanding the API until _after_ stabilization, as was the case with `std::future`. __edit:__ the feature gate has been changed to `async_stream` to match the feature gate proposed in the RFC. ## Conclusion This PR introduces `core::stream::{Stream, Next}` and re-exports it from `std` as `std::stream::{Stream, Next}`. Landing `Stream` in the stdlib has been a mult-year process; and it's incredibly exciting for this to finally happen! --- r? `````@KodrAus````` cc/ `````@rust-lang/wg-async-foundations````` `````@rust-lang/libs`````
2021-01-29btree: use Option's unwrap_unchecked()Miguel Ojeda-31/+13
Now that https://github.com/rust-lang/rust/issues/81383 is available, start using it. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-01-29rename raw_const/mut -> const/mut_addr_of, and stabilize themRalf Jung-9/+8
2021-01-29Updated Vec::splice documentationChan Kwan Yin-1/+1
Replacing with equal number of values does not increase the length of the vec. Reference: https://stackoverflow.com/a/62559271/3990767
2021-01-29Auto merge of #81073 - ssomers:btree_owned_root_vs_dying, r=Mark-Simulacrumbors-32/+73
BTreeMap: prevent tree from ever being owned by non-root node This introduces a new marker type, `Dying`, which is used to note trees which are in the process of deallocation. On such trees, some fields may be in an inconsistent state as we are deallocating the tree. Unfortunately, there's not a great way to express conditional unsafety, so the methods for traversal can cause UB if not invoked correctly, but not marked as such. This is not a regression from the previous state, but rather isolates the destructive methods to solely being called on the dying state.
2021-01-27Auto merge of #81335 - thomwiggers:no-panic-shrink-to, r=Mark-Simulacrumbors-16/+12
Trying to shrink_to greater than capacity should be no-op Per the discussion in https://github.com/rust-lang/rust/issues/56431, `shrink_to` shouldn't panic if you try to make a vector shrink to a capacity greater than its current capacity.
2021-01-27Rollup merge of #81191 - ssomers:btree_more_order_chaos, r=Mark-SimulacrumYuki Okushi-1/+87
BTreeMap: test all borrowing interfaces and test more chaotic order behavior Inspired by #81169, test what happens if you mess up order of the type with which you search (as opposed to the key type). r? `@Mark-Simulacrum`
2021-01-26BTreeMap: stop tree from being owned by non-root nodeStein Somers-32/+73
2021-01-26shrink_to shouldn't panic on len greater than capacityThom Wiggers-16/+12
2021-01-26Auto merge of #81217 - ssomers:btree_bring_back_the_slice, r=Mark-Simulacrumbors-43/+23
BTreeMap: bring back the key slice for immutable lookup Pave the way for binary search, by reverting a bit of #73971, which banned `keys` for misbehaving while it was defined for every `BorrowType`. Adding some `debug_assert`s along the way. r? `@Mark-Simulacrum`
2021-01-26Auto merge of #79113 - andjo403:raw_vec_ptr, r=m-ou-sebors-0/+1
mark raw_vec::ptr with inline when a lot of vectors is used in a enum as in the example in #66617 if this function is not inlined and multiple cgus is used this results in huge compile times. with this fix the compile time is 6s from minutes for the example in #66617. I did not have the patience to wait for it to compile for more then 3 min.
2021-01-24BTreeMap: lightly refactor the split_off implementationStein Somers-42/+67
2021-01-23Rollup merge of #81170 - xfix:vecdeque-bug-fix, r=sfacklerJonas Schievink-3/+47
Avoid hash_slice in VecDeque's Hash implementation Fixes #80303.
2021-01-24Fix and simplifyoxalica-22/+22
2021-01-22Auto merge of #79233 - yoshuawuyts:alloc-doc-alias, r=GuillaumeGomezbors-2/+16
Add doc aliases for memory allocations This patch adds doc aliases for various C allocation functions, making it possible to search for the C-equivalent of a function and finding the (safe) Rust counterpart: - `Vec::with_capacity` / `Box::new` / `vec!` -> alloc + malloc, allocates memory - `Box::new_zeroed` -> calloc, allocates zeroed-out memory - `Vec::{reserve,reserve_exact,try_reserve_exact,shrink_to_fit,shrink_to}` -> realloc, reallocates a previously allocated slice of memory It's worth noting that `Vec::new` does not allocate, so we don't link to it. Instead people are probably looking for `Vec::with_capacity` or `vec!`. I hope this will allow people comfortable with the system allocation APIs to make it easier to find what they may be looking for. Thanks!
2021-01-22Add doc aliases for memory allocationsYoshua Wuyts-2/+16
- Vec::with_capacity / Box::new -> alloc + malloc - Box::new_zeroed -> calloc - Vec::{reserve,reserve_exact,try_reserve_exact,shrink_to_fit,shrink_to} -> realloc
2021-01-22Add `core::stream::Stream`Yoshua Wuyts-0/+15
This patch adds the `core::stream` submodule and implements `core::stream::Stream` in accordance with RFC2996. Add feedback from @camelid
2021-01-22Rollup merge of #81242 - jyn514:const-cap, r=sfacklerMara Bos-16/+14
Enforce statically that `MIN_NON_ZERO_CAP` is calculated at compile time Previously, it would usually get computed by LLVM, but this enforces it. This removes the need for the comment saying "LLVM is smart enough". I don't expect this to make a performance difference, but I do think it makes the performance properties easier to reason about.
2021-01-22Rollup merge of #81241 - m-ou-se:force-expr-macro-rules, r=oli-obkMara Bos-10/+13
Turn alloc's force_expr macro into a regular macro_rules. This turns `alloc`'s `force_expr` macro into a regular `macro_rules`. Otherwise rust-analyzer doesn't understand `vec![]`. See https://github.com/rust-analyzer/rust-analyzer/issues/7349 and https://github.com/rust-lang/rust/pull/81080#issuecomment-764741721 Edit: See https://github.com/rust-lang/rust/pull/81241#issuecomment-764812660 for a discussion of alternatives.