about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
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
2021-02-09Add `Box::into_inner`.Charles Lew-0/+17
2021-02-09Rollup merge of #81826 - tesuji:inline-box-zeros, r=AmanieuDylan DPC-2/+12
Prefer match over combinators to make some Box methods inlineable Hopefully this patch would make two snippets generated identical code: <https://rust.godbolt.org/z/fjrj4E>.
2021-02-08Auto merge of #81361 - ssomers:btree_drainy_refactor_7, r=Mark-Simulacrumbors-42/+67
BTreeMap: lightly refactor the split_off implementation r? `@Mark-Simulacrum`
2021-02-08Auto merge of #79245 - ssomers:btree_curb_ord_bound, r=dtolnaybors-20/+22
BTree: remove Ord bound where it is absent elsewhere Some btree methods don't really need an Ord bound and don't have one, while some methods that more obviously don't need it, do have one. An example of the former is `iter`, even though it explicitly exposes the work of the Ord implementation (["sorted by key"](https://doc.rust-lang.org/std/collections/struct.BTreeMap.html#method.iter) - but I'm not suggesting it should have the Ord bound). An example of the latter is `new`, which doesn't involve any keys whatsoever.
2021-02-07Rollup merge of #81526 - ojeda:btree-use-unwrap_unchecked, r=scottmcmGuillaume Gomez-31/+13
btree: use Option's unwrap_unchecked() Now that https://github.com/rust-lang/rust/issues/81383 is available, start using it.
2021-02-06Fix doc test for Vec::retain(), now passes clippy::eval_order_dependenceSteve Heindel-3/+4
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