about summary refs log tree commit diff
path: root/library/alloc
AgeCommit message (Collapse)AuthorLines
2021-06-02Replace IntoIter::new with IntoIterator::into_iter in stdMuhammad Mominul Huque-2/+1
2021-05-31Update documentation of SpecFromIter to reflect the removed implsFrank Steffahn-3/+1
2021-05-31Remove unnecessary SpecFromIter implsFrank Steffahn-31/+0
2021-05-31Auto merge of #85814 - steffahn:fix_linked_list_itermut_debug, r=m-ou-sebors-7/+20
Fix unsoundness of Debug implementation for linked_list::IterMut Fix #85813, new `marker` field follows the example of `linked_list::Iter`.
2021-05-30Rollup merge of #85817 - r00ster91:patch-9, r=dtolnayGuillaume Gomez-1/+1
Fix a typo See also: #85737
2021-05-30Rollup merge of #85801 - WaffleLapkin:master, r=joshtriplettGuillaume Gomez-0/+37
Add `String::extend_from_within` This PR adds `String::extend_from_within` function under the `string_extend_from_within` feature gate similar to the [`Vec::extend_from_within`] function. ```rust // String pub fn extend_from_within<R>(&mut self, src: R) where R: RangeBounds<usize>; ``` [`Vec::extend_from_within`]: https://github.com/rust-lang/rust/issues/81656
2021-05-30Improve Debug impls for LinkedList reference iterators to show itemsFrank Steffahn-2/+18
2021-05-30Fix a typor00ster-1/+1
2021-05-29Fix unsoundness of Debug implementation for linked_list::IterMutFrank Steffahn-6/+3
2021-05-29Add `String::extend_from_within`Waffle-0/+37
This patch adds `String::extend_from_within` function under the `string_extend_from_within` feature gate similar to the `Vec::extend_from_within` function.
2021-05-27Revert "Auto merge of #83770 - the8472:tra-extend, r=Mark-Simulacrum"The8472-59/+25
Due to a performance regression that didn't show up in the original perf run this reverts commit 9111b8ae9793f18179a1336417618fc07a9cac85, reversing changes made to 9a700d2947f2d7f97a2c0dfca3117a8dcc255bdd.
2021-05-27Auto merge of #85737 - scottmcm:vec-calloc-option-nonzero, r=m-ou-sebors-0/+33
Enable Vec's calloc optimization for Option<NonZero> Someone on discord noticed that `vec![None::<NonZeroU32>; N]` wasn't getting the optimization, so here's a PR 🙃 We can certainly do this in the standard library because we know for sure this is ok, but I think it's also a necessary consequence of documented guarantees like those in https://doc.rust-lang.org/std/option/#representation and https://doc.rust-lang.org/core/num/struct.NonZeroU32.html It feels weird to do this without adding a test, but I wasn't sure where that would belong. Is it worth adding codegen tests for these?
2021-05-26Enable Vec's calloc optimization for Option<NonZero>Scott McMurray-0/+33
2021-05-26Auto merge of #83770 - the8472:tra-extend, r=Mark-Simulacrumbors-25/+59
Add `TrustedRandomAccess` specialization for `Vec::extend()` This should do roughly the same as the `TrustedLen` specialization but result in less IR by using `__iterator_get_unchecked` instead of `Iterator::for_each` Conflicting specializations are manually prioritized by grouping them under yet another helper trait.
2021-05-26Document `From` impls for cow.rsDeadbeef-0/+18
2021-05-26Rollup merge of #85625 - SkiFire13:fix-85613-vec-dedup-drop-panics, r=nagisaDylan DPC-25/+28
Prevent double drop in `Vec::dedup_by` if a destructor panics Fixes #85613
2021-05-26Document `From` impls in string.rsDeadbeef-7/+43
2021-05-26Rollup merge of #85666 - fee1-dead:document-shared-from-cow, r=dtolnayYuki Okushi-0/+24
Document shared_from_cow functions
2021-05-26Auto merge of #85535 - dtolnay:weakdangle, r=kennytmbors-2/+32
Weak's type parameter may dangle on drop Way back in https://github.com/rust-lang/rust/commit/34076bc0c9fb9ee718e1cebc407547eef730a080, #\[may_dangle\] was added to Rc\<T\> and Arc\<T\>'s Drop impls. That appears to have been because a test added in #28929 used Arc and Rc with dangling references at drop time. However, Weak was not covered by that test, and therefore no #\[may_dangle\] was forced to be added at the time. As far as dropping, Weak has *even less need* to interact with the T than Rc and Arc do. Roughly speaking #\[may_dangle\] describes generic parameters that the outer type's Drop impl does not interact with except by possibly dropping them; no other interaction (such as trait method calls on the generic type) is permissible. It's clear this applies to Rc's and Arc's drop impl, which sometimes drop T but otherwise do not interact with one. It applies *even more* to Weak. Dropping a Weak cannot ever cause T's drop impl to run. Either there are strong references still in existence, in which case better not drop the T. Or there are no strong references still in existence, in which case the T would already have been dropped previously by the drop of the last strong count.
2021-05-25Document shared_from_cow functionsDeadbeef-0/+24
2021-05-24remove cfg(bootstrap)Pietro Albini-3/+1
2021-05-24Make Vec::dedup panicking test actually detect double panicsGiacomo Stevanato-23/+25
2021-05-24Avoid a double drop in Vec::dedup if a destructor panicsGiacomo Stevanato-2/+3
2021-05-21Remove surplus prepend LinkedList fnJubilee Young-21/+0
Originally committed to Rust in 2013, it is identical to append with a reversed order of arguments.
2021-05-20Weak's type parameter may dangle on dropDavid Tolnay-2/+2
2021-05-20Add Weak may_dangle testsDavid Tolnay-0/+30
2021-05-20Auto merge of #85391 - Mark-Simulacrum:opt-tostring, r=scottmcmbors-2/+3
Avoid zero-length memcpy in formatting This has two separate and somewhat orthogonal commits. The first change adjusts the ToString general impl for all types that implement Display; it no longer uses the full format machinery, rather directly falling onto a `std::fmt::Display::fmt` call. The second change directly adjusts the general core::fmt::write function which handles the production of format_args! to avoid zero-length push_str calls. Both changes target the fact that push_str will still call memmove internally (or a similar function), as it doesn't know the length of the passed string. For zero-length strings in particular, this is quite expensive, and even for very short (several bytes long) strings, this is also expensive. Future work in this area may wish to have us fallback to write_char or similar, which may be cheaper on the (typically) short strings between the interpolated pieces in format_args!.
2021-05-19from review: more robust testthe8472-2/+2
This also checks the contents and not only the capacity in case IntoIter's clone implementation is changed to add capacity at the end. Extra capacity at the beginning would be needed to make InPlaceIterable work. Co-authored-by: Giacomo Stevanato <giaco.stevanato@gmail.com>
2021-05-19add regression testThe8472-0/+12
2021-05-19remove InPlaceIterable marker from Peekable due to unsoundnessThe8472-2/+0
The unsoundness is not in Peekable per se, it rather is due to the interaction between Peekable being able to hold an extra item and vec::IntoIter's clone implementation shortening the allocation. An alternative solution would be to change IntoIter's clone implementation to keep enough spare capacity available.
2021-05-18Auto merge of #84767 - scottmcm:try_trait_actual, r=lcnrbors-3/+4
Implement the new desugaring from `try_trait_v2` ~~Currently blocked on https://github.com/rust-lang/rust/issues/84782, which has a PR in https://github.com/rust-lang/rust/pull/84811~~ Rebased atop that fix. `try_trait_v2` tracking issue: https://github.com/rust-lang/rust/issues/84277 Unfortunately this is already touching a ton of things, so if you have suggestions for good ways to split it up, I'd be happy to hear them. (The combination between the use in the library, the compiler changes, the corresponding diagnostic differences, even MIR tests mean that I don't really have a great plan for it other than trying to have decently-readable commits. r? `@ghost` ~~(This probably shouldn't go in during the last week before the fork anyway.)~~ Fork happened.
2021-05-17Optimize default ToString implMark Rousskov-2/+3
This avoids a zero-length write_str call, which boils down to a zero-length memmove and ultimately costs quite a few instructions on some workloads. This is approximately a 0.33% instruction count win on diesel-check.
2021-05-16mark internal inplace_iteration traits as hiddenThe8472-0/+4
2021-05-13Add support for const operands and options to global_asm!Amanieu d'Antras-1/+1
On x86, the default syntax is also switched to Intel to match asm!
2021-05-11Auto merge of #84904 - ssomers:btree_drop_kv_in_place, r=Mark-Simulacrumbors-45/+95
BTree: no longer copy keys and values before dropping them When dropping BTreeMap or BTreeSet instances, keys-value pairs are up to now each copied and then dropped, at least according to source code. This is because the code for dropping and for iterators is shared. This PR postpones the treatment of doomed key-value pairs from the intermediate functions `deallocating_next`(`_back`) to the last minute, so the we can drop the keys and values in place. According to the library/alloc benchmarks, this does make a difference, (and a positive difference with an `#[inline]` on `drop_key_val`). It does not change anything for #81444 though. r? `@Mark-Simulacrum`
2021-05-10Document Rc::fromDeadbeef-0/+13
2021-05-09PR feedbackScott McMurray-2/+2
2021-05-07BTree: no longer copy keys and values before dropping themStein Somers-45/+95
2021-05-06Perf Experiment: Wait, what if I just skip the trait aliasScott McMurray-4/+4
2021-05-06Bootstrapping preparation for the libraryScott McMurray-3/+4
Since just `ops::Try` will need to change meaning.
2021-05-06Rollup merge of #84328 - Folyd:stablize_map_into_keys_values, r=m-ou-seDylan DPC-16/+14
Stablize {HashMap,BTreeMap}::into_{keys,values} I would propose to stabilize `{HashMap,BTreeMap}::into_{keys,values}`( aka. `map_into_keys_values`). Closes #75294.
2021-05-05alloc: Add unstable Cfg feature `no-global_oom_handling`John Ericson-27/+322
For certain sorts of systems, programming, it's deemed essential that all allocation failures be explicitly handled where they occur. For example, see Linus Torvald's opinion in [1]. Merely not calling global panic handlers, or always `try_reserving` first (for vectors), is not deemed good enough, because the mere presence of the global OOM handlers is burdens static analysis. One option for these projects to use rust would just be to skip `alloc`, rolling their own allocation abstractions. But this would, in my opinion be a real shame. `alloc` has a few `try_*` methods already, and we could easily have more. Features like custom allocator support also demonstrate and existing to support diverse use-cases with the same abstractions. A natural way to add such a feature flag would a Cargo feature, but there are currently uncertainties around how std library crate's Cargo features may or not be stable, so to avoid any risk of stabilizing by mistake we are going with a more low-level "raw cfg" token, which cannot be interacted with via Cargo alone. Note also that since there is no notion of "default cfg tokens" outside of Cargo features, we have to invert the condition from `global_oom_handling` to to `not(no_global_oom_handling)`. This breaks the monotonicity that would be important for a Cargo feature (i.e. turning on more features should never break compatibility), but it doesn't matter for raw cfg tokens which are not intended to be "constraint solved" by Cargo or anything else. To support this use-case we create a new feature, "global-oom-handling", on by default, and put the global OOM handler infra and everything else it that depends on it behind it. By default, nothing is changed, but users concerned about global handling can make sure it is disabled, and be confident that all OOM handling is local and explicit. For this first iteration, non-flat collections are outright disabled. `Vec` and `String` don't yet have `try_*` allocation methods, but are kept anyways since they can be oom-safely created "from parts", and we hope to add those `try_` methods in the future. [1]: https://lore.kernel.org/lkml/CAHk-=wh_sNLoz84AUUzuqXEsYH35u=8HV3vK-jbRbJ_B-JjGrg@mail.gmail.com/
2021-05-05Bump map_into_keys_values stable version to 1.54.0.Mara Bos-14/+14
2021-05-03Fix stability attributes of byte-to-string specializationLingMan-2/+2
2021-05-03Auto merge of #84842 - blkerby:null_lowercase, r=joshtriplettbors-1/+1
Replace 'NULL' with 'null' This replaces occurrences of "NULL" with "null" in docs, comments, and compiler error/lint messages. This is for the sake of consistency, as the lowercase "null" is already the dominant form in Rust. The all-caps NULL looks like the C macro (or SQL keyword), which seems out of place in a Rust context, given that NULL does not exist in the Rust language or standard library (instead having [`ptr::null()`](https://doc.rust-lang.org/stable/std/ptr/fn.null.html)).
2021-05-02Change 'NULL' to 'null'Brent Kerby-1/+1
2021-05-02Auto merge of #82576 - gilescope:to_string, r=Amanieubors-0/+41
i8 and u8::to_string() specialisation (far less asm). Take 2. Around 1/6th of the assembly to without specialisation. https://godbolt.org/z/bzz8Mq (partially fixes #73533 )
2021-04-28Minor grammar tweaks for readabilityBen-Lichtman-4/+4
2021-04-28Stabilize vec_extend_from_withinAmanieu d'Antras-5/+1
2021-04-26Auto merge of #84174 - camsteffen:slice-diag, r=Mark-Simulacrumbors-1/+0
Remove slice diagnostic item ...because it is unusally placed on an impl and is redundant with a lang item. Depends on rust-lang/rust-clippy#7074 (next clippy sync). ~I expect clippy tests to fail in the meantime.~ Nope tests passed... CC `@flip1995`