about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
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.
2021-01-21Rename alloc::force_expr to __rust_force_expr.Mara Bos-4/+4
2021-01-21Turn alloc's force_expr macro into a regular macro_rules!{}.Mara Bos-10/+13
Otherwise rust-analyzer doesn't understand vec![].
2021-01-21Enforce statically that `MIN_NON_ZERO_CAP` is calculated at compile timeJoshua Nelson-16/+14
Previously, it would usually get computed by LLVM, but this enforces it.
2021-01-21Rollup merge of #81179 - CPerezz:fix_interal_doc_warns, r=jyn514Yuki Okushi-1/+1
Fix broken links with `--document-private-items` in the standard library As it was suggested in #81037 `SpecFromIter` is not in the scope and therefore we get a warning when we try to do document private intems in `rust/library/alloc/`. This addresses #81037 by adding the trait in the scope as ```@jyn514``` suggested and also adding an `allow(unused_imports)` flag so that the compiler does not complain, Since the trait is not used per se in the code, it's just needed to have properly documented docs.
2021-01-21Rollup merge of #80601 - steffahn:improve_format_string_grammar, r=m-ou-seYuki Okushi-4/+5
Improve grammar in documentation of format strings The docs previously were * using some weird `<` and `>` around some nonterminals * _correct me if these **did** have any meaning_ * using of a (not explicitly defined) `text` nonterminal that didn’t explicitly disallow productions containing `'{'` or `'}'` * incorrect in not allowing for `x?` and `X?` productions of `type` * unnecessarily ambiguous, both * allowing `type` to be `''`, and * using an optional `[type]` * using inconsistent underscore/hyphenation style between `format_string` and `format_spec` vs `maybe-format` _Rendered:_ ![Screenshot_20210101_230901](https://user-images.githubusercontent.com/3986214/103447038-69d7a180-4c86-11eb-8fa0-0a6160a7ff7a.png) _(current docs: https://doc.rust-lang.org/nightly/std/fmt/#syntax)_ ```@rustbot``` modify labels: T-doc
2021-01-21Remove link to current sectionIvan Tham-2/+1
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2021-01-20BTreeMap: bring back the key slice for immutable lookupStein Somers-43/+23
2021-01-20Add more details explaning the Vec visualizationIvan Tham-20/+22
Suggested by oli-obk
2021-01-20Add Vec visualization to understand capacityIvan Tham-0/+21
Visualize vector while differentiating between stack and heap. Inspired by cheats.rs, as this is probably the first place beginner go, they could understand stack and heap, length and capacity with this. Not sure if adding this means we should add to other places too. Superseeds #76066
2021-01-19BTreeMap: compile-test all borrowing interfaces and test more chaotic orderStein Somers-1/+87
2021-01-19Add SpecFromIter ref in the comments directlyCPerezz-3/+1
2021-01-19Rollup merge of #81115 - ssomers:btree_drainy_refactor_4, r=Mark-SimulacrumGuillaume Gomez-121/+8
BTreeMap: prefer bulk_steal functions over specialized ones The `steal_` functions (apart from their return value) are basically specializations of the more general `bulk_steal_` functions. This PR removes the specializations. The library/alloc benchmarks say this is never slower and up to 6% faster. r? ``@Mark-Simulacrum``
2021-01-19Rollup merge of #81112 - m-ou-se:alloc-std-ops-reexport, r=KodrAusGuillaume Gomez-5/+0
Remove unused alloc::std::ops re-export. Removes unused re-export in alloc/lib.rs.
2021-01-18Fix soundness issue for `replace_range` and `range`dylni-6/+20
2021-01-18Fix internal rustdoc broken linksCPerezz-0/+2
As it was suggested in #81037 `SpecFromIter` is not in the scope and therefore (even it should fail), we get a warning when we try do document private intems in `rust/library/alloc/`. This fixes #81037 by adding the trait in the scope and also adding an `allow(unused_imports)` flag so that the compiler does not complain, Since the trait is not used per se in the code, it's just needed to have properly documented docs.
2021-01-18Avoid hash_slice in VecDeque's Hash implementationKonrad Borowski-3/+47
Fixes #80303.
2021-01-18BTreeMap: prefer bulk_steal functions over specialized onesStein Somers-121/+8
2021-01-18BTreeMap: convert search functions to methodsStein Somers-83/+83
2021-01-18Auto merge of #81090 - ssomers:btree_drainy_refactor_2, r=Mark-Simulacrumbors-34/+60
BTreeMap: offer merge in variants with more clarity r? `@Mark-Simulacrum`