about summary refs log tree commit diff
path: root/library/alloc/tests
AgeCommit message (Collapse)AuthorLines
2021-10-04Rollup merge of #87993 - kornelski:try_reserve_stable, r=joshtriplettJubilee-1/+0
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 #89443 - cuviper:btree-hash-len, r=dtolnayJubilee-2/+12
Include the length in BTree hashes This change makes it consistent with `Hash` for all other collections.
2021-10-04Stabilize try_reserveKornel-1/+0
2021-10-01Include the length in BTree hashesJosh Stone-2/+12
This change makes it consistent with `Hash` for all other collections.
2021-09-30implement advance_(back_)_by on more iteratorsThe8472-0/+19
2021-09-17Stabilize `Iterator::map_while`Maybe Waffle-1/+0
2021-09-01Rollup merge of #88040 - nbdd0121:btreemap, r=m-ou-seMara Bos-28/+4
BTree: remove Ord bound from new `K: Ord` bound is unnecessary on `BTree{Map,Set}::new` and their `Default` impl. No elements exist so there are nothing to compare anyway, so I don't think "future proof" would be a blocker here. This is analogous to `HashMap::new` not having a `K: Eq + Hash` bound. #79245 originally does this and for some reason drops the change to `new` and `Default`. I can see why changes to other methods like `entry` or `symmetric_difference` need to be careful but I couldn't find out any reason not to do it on `new`. Removing the bound also makes the stabilisation of `const fn new` not depending on const trait bounds. cc `@steffahn` who suggests me to make this PR. r? `@dtolnay`
2021-08-24Fix grammarest31-4/+4
2021-08-18BTree: remove Ord bound from newGary Guo-28/+4
2021-08-17Constified `Default` implementationsDeadbeef-13/+14
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-16Rollup merge of #88030 - fee1-dead:fixme, r=oli-obkMara Bos-3/+1
Assign FIXMEs to me and remove obsolete ones Also fixed capitalization of documentation We also don't need to transform predicates to be non-const since we basically ignore const predicates in non-const contexts. r? `````@oli-obk`````
2021-08-15Auto merge of #87974 - steffahn:slice_split_size_hints, r=dtolnaybors-0/+61
Test and fix `size_hint` for slice’s [r]split* iterators Adds extensive test (of `size_hint`) for all the _[r]split*_ iterators. Fixes `size_hint` upper bound for _split_inclusive*_ iterators which was one higher than necessary for non-empty slices. Fixes `size_hint` lower bound for _[r]splitn*_ iterators when _n == 0_, which was one too high. **Lower bound being one too high was a logic error, violating the correctness condition of `size_hint`.** _Edit:_ I’ve opened an issue for that bug, so this PR fixes #87978
2021-08-14Assign FIXMEs to me and remove obsolete onesDeadbeef-3/+1
Also fixed capitalization of documentation
2021-08-13Improve wording, correct -> tight.Frank Steffahn-6/+6
2021-08-13Consistent use of `impl Trait` arguments in the test's helper function.Frank Steffahn-5/+1
2021-08-13allow incomplete features for nowDeadbeef-0/+2
2021-08-13Moved ui testDeadbeef-0/+56
2021-08-12Rewrite test from previous commit but without using macros.Frank Steffahn-64/+55
2021-08-12Test and fix size_hint for slice's [r]split* iteratorsFrank Steffahn-0/+74
Adds extensive test for all the [r]split* iterators. Fixes size_hint upper bound for split_inclusive* iterators which was one higher than necessary for non-empty slices. Fixes size_hint lower bound for [r]splitn* iterators when n==0, which was one too high.
2021-08-07Use assert_matches! instead of if let {} elseKornel-292/+269
2021-08-07Auto merge of #87408 - kornelski:try_reserve_error, r=yaahcbors-87/+197
Hide allocator details from TryReserveError I think there's [no need for TryReserveError to carry detailed information](https://github.com/rust-lang/rust/issues/48043#issuecomment-825139280), but I wouldn't want that issue to delay stabilization of the `try_reserve` feature. So I'm proposing to stabilize `try_reserve` with a `TryReserveError` as an opaque structure, and if needed, expose error details later. This PR moves the `enum` to an unstable inner `TryReserveErrorKind` that lives under a separate feature flag. `TryReserveErrorKind` could possibly be left as an implementation detail forever, and the `TryReserveError` get methods such as `allocation_size() -> Option<usize>` or `layout() -> Option<Layout>` instead, or the details could be dropped completely to make try-reserve errors just a unit struct, and thus smaller and cheaper.
2021-07-29Fix may not to appropriate might not or must notAli Malik-1/+1
2021-07-24Hide allocator details from TryReserveErrorKornel-87/+197
2021-07-11Add test for the fixAlexis Bourget-0/+41
2021-06-18Lint for unused borrows as part of UNUSED_MUST_USEhi-rustin-10/+10
2021-06-06Rollup merge of #85930 - mominul:array_into_iter, r=m-ou-seYuki Okushi-5/+5
Update standard library for IntoIterator implementation of arrays This PR partially resolves issue #84513 of updating the standard library part. I haven't found any remaining doctest examples which are using iterators over e.g. &i32 instead of just i32 in the standard library. Can anyone point me to them if there's remaining any? Thanks! r? ```@m-ou-se```
2021-06-02Stabilize `vecdeque_binary_search`SOFe-1/+0
2021-06-02Update expressions where we can use array's IntoIterator implementationMuhammad Mominul Huque-5/+5
2021-05-26Rollup merge of #85625 - SkiFire13:fix-85613-vec-dedup-drop-panics, r=nagisaDylan DPC-23/+25
Prevent double drop in `Vec::dedup_by` if a destructor panics Fixes #85613
2021-05-24Make Vec::dedup panicking test actually detect double panicsGiacomo Stevanato-23/+25
2021-05-20Add Weak may_dangle testsDavid Tolnay-0/+30
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-1/+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-04-28Stabilize vec_extend_from_withinAmanieu d'Antras-1/+0
2021-04-22Add better test for BinaryHeap::retain.Mara Bos-3/+16
2021-04-15VecDeque: Add partition_point() #78021Vojtech Kral-0/+18
2021-04-04Rollup merge of #83827 - the8472:fix-inplace-panic-on-drop, r=RalfJungDylan DPC-1/+10
cleanup leak after test to make miri happy Contains changes that were requested in #83629 but didn't make it into the rollup. r? `````@RalfJung`````
2021-04-04Rollup merge of #81619 - SkiFire13:resultshunt-inplace, r=the8472Dylan DPC-2/+2
Implement `SourceIterator` and `InPlaceIterable` for `ResultShunt`
2021-04-04suggestion from reviewthe8472-1/+1
Co-authored-by: Ralf Jung <post@ralfj.de>
2021-04-04cleanup leak after test to make miri happyThe8472-1/+10
2021-04-02Rollup merge of #83629 - the8472:fix-inplace-panic-on-drop, r=m-ou-seDylan DPC-1/+37
Fix double-drop in `Vec::from_iter(vec.into_iter())` specialization when items drop during panic This fixes the double-drop but it leaves a behavioral difference compared to the default implementation intact: In the default implementation the source and the destination vec are separate objects, so they get dropped separately. Here they share an allocation and the latter only exists as a pointer into the former. So if dropping the former panics then this fix will leak more items than the default implementation would. Is this acceptable or should the specialization also mimic the default implementation's drops-during-panic behavior? Fixes #83618 `@rustbot` label T-libs-impl
2021-03-30Rollup merge of #82331 - frol:feat/std-binary-heap-as-slice, r=AmanieuDylan DPC-0/+1
alloc: Added `as_slice` method to `BinaryHeap` collection I initially asked about whether it is useful addition on https://internals.rust-lang.org/t/should-i-add-as-slice-method-to-binaryheap/13816, and it seems there were no objections, so went ahead with this PR. > There is [`BinaryHeap::into_vec`](https://doc.rust-lang.org/std/collections/struct.BinaryHeap.html#method.into_vec), but it consumes the value. I wonder if there is API design limitation that should be taken into account. Implementation-wise, the inner buffer is just a Vec, so it is trivial to expose as_slice from it. Please, guide me through if I need to add tests or something else. UPD: Tracking issue #83659
2021-03-29add testcase for double-drop during Vec in-place collectionThe8472-1/+37
2021-03-28Auto merge of #81728 - Qwaz:fix-80335, r=joshtriplettbors-0/+30
Fixes API soundness issue in join() Fixes #80335
2021-03-27Auto merge of #78618 - workingjubilee:ieee754-fmt, r=m-ou-sebors-2/+1
Add IEEE 754 compliant fmt/parse of -0, infinity, NaN This pull request improves the Rust float formatting/parsing libraries to comply with IEEE 754's formatting expectations around certain special values, namely signed zero, the infinities, and NaN. It also adds IEEE 754 compliance tests that, while less stringent in certain places than many of the existing flt2dec/dec2flt capability tests, are intended to serve as the beginning of a roadmap to future compliance with the standard. Some relevant documentation is also adjusted with clarifying remarks. This PR follows from discussion in https://github.com/rust-lang/rfcs/issues/1074, and closes #24623. The most controversial change here is likely to be that -0 is now printed as -0. Allow me to explain: While there appears to be community support for an opt-in toggle of printing floats as if they exist in the naively expected domain of numbers, i.e. not the extended reals (where floats live), IEEE 754-2019 is clear that a float converted to a string should be capable of being transformed into the original floating point bit-pattern when it satisfies certain conditions (namely, when it is an actual numeric value i.e. not a NaN and the original and destination float width are the same). -0 is given special attention here as a value that should have its sign preserved. In addition, the vast majority of other programming languages not only output `-0` but output `-0.0` here. While IEEE 754 offers a broad leeway in how to handle producing what it calls a "decimal character sequence", it is clear that the operations a language provides should be capable of round tripping, and it is confusing to advertise the f32 and f64 types as binary32 and binary64 yet have the most basic way of producing a string and then reading it back into a floating point number be non-conformant with the standard. Further, existing documentation suggested that e.g. -0 would be printed with -0 regardless of the presence of the `+` fmt character, but it prints "+0" instead if given such (which was what led to the opening of #24623). There are other parsing and formatting issues for floating point numbers which prevent Rust from complying with the standard, as well as other well-documented challenges on the arithmetic level, but I hope that this can be the beginning of motion towards solving those challenges.
2021-03-26Update char::escape_debug_ext to handle different escapes in strings vs. charsÖmer Sinan Ağacan-4/+1
Fixes #83046 The program fn main() { println!("{:?}", '"'); println!("{:?}", "'"); } would previously print '\"' "\'" With this patch it now prints: '"' "'"
2021-03-24Revert "Revert stabilizing integer::BITS."Mara Bos-1/+0
2021-03-22Preserve signed zero on roundtripJubilee Young-2/+1
This commit removes the previous mechanism of differentiating between "Debug" and "Display" formattings for the sign of -0 so as to comply with the IEEE 754 standard's requirements on external character sequences preserving various attributes of a floating point representation. In addition, numerous tests are fixed.
2021-03-19Auto merge of #71780 - jcotton42:string_remove_matches, r=joshtriplettbors-0/+28
Implement String::remove_matches Closes #50206. I lifted the function help from `@frewsxcv's` original PR (#50015), hope they don't mind. I'm also wondering whether it would be useful for `remove_matches` to collect up the removed substrings into a `Vec` and return them, right now they're just overwritten by the copy and lost.