about summary refs log tree commit diff
path: root/src/liballoc/tests
AgeCommit message (Collapse)AuthorLines
2018-03-16Auto merge of #49051 - kennytm:rollup, r=kennytmbors-18/+2
Rollup of 17 pull requests - Successful merges: #48706, #48875, #48892, #48922, #48957, #48959, #48961, #48965, #49007, #49024, #49042, #49050, #48853, #48990, #49037, #49049, #48972 - Failed merges:
2018-03-15setting ABORTING_MALLOC for asmjs backendsnf-18/+2
2018-03-15Auto merge of #47813 - kennytm:stable-incl-range, r=nrcbors-1/+2
Stabilize inclusive range (`..=`) Stabilize the followings: * `inclusive_range` — The `std::ops::RangeInclusive` and `std::ops::RangeInclusiveTo` types, except its fields (tracked by #49022 separately). * `inclusive_range_syntax` — The `a..=b` and `..=b` expression syntax * `dotdoteq_in_patterns` — Using `a..=b` in a pattern cc #28237 r? @rust-lang/lang
2018-03-15Keep the fields of RangeInclusive unstable.kennytm-0/+1
2018-03-15Stabilize `inclusive_range_syntax` language feature.kennytm-1/+1
Stabilize the syntax `a..=b` and `..=b`.
2018-03-14try_reserve: disabling tests for asmjs, blocked by #48968snf-2/+18
2018-03-14implementing fallible allocation API (try_reserve) for Vec, String and HashMapsnf-1/+580
2018-03-11Update Cargo submoduleAlex Crichton-1/+247
Required moving all fulldeps tests depending on `rand` to different locations as now there's multiple `rand` crates that can't be implicitly linked against.
2018-02-22Stabilize [T]::rotate_{left,right}Corey Farwell-1/+0
https://github.com/rust-lang/rust/issues/41891
2018-01-23Stabilized `#[repr(align(x))]` attribute (RFC 1358)Cameron Hart-1/+0
2018-01-15Rollup merge of #47126 - sdroege:exact-chunks, r=blusskennytm-2/+59
Add slice::ExactChunks and ::ExactChunksMut iterators These guarantee that always the requested slice size will be returned and any leftoever elements at the end will be ignored. It allows llvm to get rid of bounds checks in the code using the iterator. This is inspired by the same iterators provided by ndarray. Fixes https://github.com/rust-lang/rust/issues/47115 I'll add unit tests for all this if the general idea and behaviour makes sense for everybody. Also see https://github.com/rust-lang/rust/issues/47115#issuecomment-354715511 for an example what this improves.
2018-01-13Add unit tests for exact_chunks/exact_chunks_mutSebastian Dröge-0/+57
These are basically modified copies of the chunks/chunks_mut tests.
2018-01-13Use assert_eq!() instead of assert!(a == b) in slice chunks_mut() unit testSebastian Dröge-2/+2
This way more useful information is printed if the test ever fails.
2018-01-09Rollup merge of #46777 - frewsxcv:frewsxcv-rotate, r=alexcrichtonCorey Farwell-8/+43
Deprecate [T]::rotate in favor of [T]::rotate_{left,right}. Background ========== Slices currently have an **unstable** [`rotate`] method which rotates elements in the slice to the _left_ N positions. [Here][tracking] is the tracking issue for this unstable feature. ```rust let mut a = ['a', 'b' ,'c', 'd', 'e', 'f']; a.rotate(2); assert_eq!(a, ['c', 'd', 'e', 'f', 'a', 'b']); ``` Proposal ======== Deprecate the [`rotate`] method and introduce `rotate_left` and `rotate_right` methods. ```rust let mut a = ['a', 'b' ,'c', 'd', 'e', 'f']; a.rotate_left(2); assert_eq!(a, ['c', 'd', 'e', 'f', 'a', 'b']); ``` ```rust let mut a = ['a', 'b' ,'c', 'd', 'e', 'f']; a.rotate_right(2); assert_eq!(a, ['e', 'f', 'a', 'b', 'c', 'd']); ``` Justification ============= I used this method today for my first time and (probably because I’m a naive westerner who reads LTR) was surprised when the docs mentioned that elements get rotated in a left-ward direction. I was in a situation where I needed to shift elements in a right-ward direction and had to context switch from the main problem I was working on and think how much to rotate left in order to accomplish the right-ward rotation I needed. Ruby’s `Array.rotate` shifts left-ward, Python’s `deque.rotate` shifts right-ward. Both of their implementations allow passing negative numbers to shift in the opposite direction respectively. The current `rotate` implementation takes an unsigned integer argument which doesn't allow the negative number behavior. Introducing `rotate_left` and `rotate_right` would: - remove ambiguity about direction (alleviating need to read docs 😉) - make it easier for people who need to rotate right [`rotate`]: https://doc.rust-lang.org/std/primitive.slice.html#method.rotate [tracking]: https://github.com/rust-lang/rust/issues/41891
2017-12-30Add trailing newlines to files which have no trailing newlines.kennytm-1/+1
2017-12-24Deprecate [T]::rotate in favor of [T]::rotate_{left,right}.Corey Farwell-8/+43
Background ========== Slices currently have an unstable [`rotate`] method which rotates elements in the slice to the _left_ N positions. [Here][tracking] is the tracking issue for this unstable feature. ```rust let mut a = ['a', 'b' ,'c', 'd', 'e', 'f']; a.rotate(2); assert_eq!(a, ['c', 'd', 'e', 'f', 'a', 'b']); ``` Proposal ======== Deprecate the [`rotate`] method and introduce `rotate_left` and `rotate_right` methods. ```rust let mut a = ['a', 'b' ,'c', 'd', 'e', 'f']; a.rotate_left(2); assert_eq!(a, ['c', 'd', 'e', 'f', 'a', 'b']); ``` ```rust let mut a = ['a', 'b' ,'c', 'd', 'e', 'f']; a.rotate_right(2); assert_eq!(a, ['e', 'f', 'a', 'b', 'c', 'd']); ``` Justification ============= I used this method today for my first time and (probably because I’m a naive westerner who reads LTR) was surprised when the docs mentioned that elements get rotated in a left-ward direction. I was in a situation where I needed to shift elements in a right-ward direction and had to context switch from the main problem I was working on and think how much to rotate left in order to accomplish the right-ward rotation I needed. Ruby’s `Array.rotate` shifts left-ward, Python’s `deque.rotate` shifts right-ward. Both of their implementations allow passing negative numbers to shift in the opposite direction respectively. Introducing `rotate_left` and `rotate_right` would: - remove ambiguity about direction (alleviating need to read docs 😉) - make it easier for people who need to rotate right [`rotate`]: https://doc.rust-lang.org/std/primitive.slice.html#method.rotate [tracking]: https://github.com/rust-lang/rust/issues/41891
2017-11-25Implement LinkedList::drain_filterJohn-John Tedro-0/+188
Relates to rust-lang/rfcs#2140 - drain_filter for all collections `drain_filter` is implemented instead of `LinkedList::remove_if` based on review feedback.
2017-11-25Auto merge of #46117 - SimonSapin:min-align, r=alexcrichtonbors-0/+49
allocators: don’t assume MIN_ALIGN for small sizes See individual commit messages.
2017-11-21fix some typosMartin Lindhe-3/+3
2017-11-20alloc_jemalloc: don’t assume MIN_ALIGN for small sizesSimon Sapin-0/+5
See previous commit’s message for what is expected of allocators in general, and https://github.com/jemalloc/jemalloc/issues/1072 for discussion of what jemalloc does specifically.
2017-11-20alloc_system: don’t assume MIN_ALIGN for small sizes, fix #45955Simon Sapin-0/+44
The GNU C library (glibc) is documented to always allocate with an alignment of at least 8 or 16 bytes, on 32-bit or 64-bit platforms: https://www.gnu.org/software/libc/manual/html_node/Aligned-Memory-Blocks.html This matches our use of `MIN_ALIGN` before this commit. However, even when libc is glibc, the program might be linked with another allocator that redefines the `malloc` symbol and friends. (The `alloc_jemalloc` crate does, in some cases.) So `alloc_system` doesn’t know which allocator it calls, and needs to be conservative in assumptions it makes. The C standard says: https://port70.net/%7Ensz/c/c11/n1570.html#7.22.3 > The pointer returned if the allocation succeeds is suitably aligned > so that it may be assigned to a pointer to any type of object > with a fundamental alignment requirement https://port70.net/~nsz/c/c11/n1570.html#6.2.8p2 > A fundamental alignment is represented by an alignment less than > or equal to the greatest alignment supported by the implementation > in all contexts, which is equal to `_Alignof (max_align_t)`. `_Alignof (max_align_t)` depends on the ABI and doesn’t seem to have a clear definition, but it seems to match our `MIN_ALIGN` in practice. However, the size of objects is rounded up to the next multiple of their alignment (since that size is also the stride used in arrays). Conversely, the alignment of a non-zero-size object is at most its size. So for example it seems ot be legal for `malloc(8)` to return a pointer that’s only 8-bytes-aligned, even if `_Alignof (max_align_t)` is 16.
2017-11-08std: Remove `rand` crate and moduleAlex Crichton-1/+3
This commit removes the `rand` crate from the standard library facade as well as the `__rand` module in the standard library. Neither of these were used in any meaningful way in the standard library itself. The only need for randomness in libstd is to initialize the thread-local keys of a `HashMap`, and that unconditionally used `OsRng` defined in the standard library anyway. The cruft of the `rand` crate and the extra `rand` support in the standard library makes libstd slightly more difficult to port to new platforms, namely WebAssembly which doesn't have any randomness at all (without interfacing with JS). The purpose of this commit is to clarify and streamline randomness in libstd, focusing on how it's only required in one location, hashmap seeds. Note that the `rand` crate out of tree has almost always been a drop-in replacement for the `rand` crate in-tree, so any usage (accidental or purposeful) of the crate in-tree should switch to the `rand` crate on crates.io. This then also has the further benefit of avoiding duplication (mostly) between the two crates!
2017-11-03Remove unused AsciiExt imports and fix tests related to ascii methodsLukas Kalbertodt-4/+0
Many AsciiExt imports have become useless thanks to the inherent ascii methods added in the last commits. These were removed. In some places, I fully specified the ascii method being called to enforce usage of the AsciiExt trait. Note that some imports are not removed but tagged with a `#[cfg(stage0)]` attribute. This is necessary, because certain ascii methods are not yet available in stage0. All those imports will be removed later. Additionally, failing tests were fixed. The test suite should exit successfully now.
2017-09-22Add support for `..=` syntaxAlex Burka-39/+39
Add ..= to the parser Add ..= to libproc_macro Add ..= to ICH Highlight ..= in rustdoc Update impl Debug for RangeInclusive to ..= Replace `...` to `..=` in range docs Make the dotdoteq warning point to the ... Add warning for ... in expressions Updated more tests to the ..= syntax Updated even more tests to the ..= syntax Updated the inclusive_range entry in unstable book
2017-09-12Disable the new Hasher tests on Emscripten.kennytm-0/+3
2017-09-12impl Hasher for {&mut Hasher, Box<Hasher>}kennytm-0/+13
2017-08-30Rollup merge of #44044 - mattico:string-splice-return, r=dtolnayAlex Crichton-17/+5
Remove Splice struct return value from String::splice The implementation is now almost identical to the one in the RFC. Fixes #44038 cc #32310
2017-08-27Move unused-extern-crate to late passTatsuyuki Ishi-5/+0
2017-08-26Remove Splice struct return value from String::spliceMatt Ickstadt-17/+5
2017-08-15Auto merge of #43245 - Gankro:drain-filter, r=sfacklerbors-0/+168
Add Vec::drain_filter This implements the API proposed in #43244. So I spent like half a day figuring out how to implement this in some awesome super-optimized unsafe way, which had me very confident this was worth putting into the stdlib. Then I looked at the impl for `retain`, and was like "oh dang". I compared the two and they basically ended up being the same speed. And the `retain` impl probably translates to DoubleEndedIter a lot more cleanly if we ever want that. So now I'm not totally confident this needs to go in the stdlib, but I've got two implementations and an amazingly robust test suite, so I figured I might as well toss it over the fence for discussion.
2017-08-15Auto merge of #43500 - murarth:string-retain, r=alexcrichtonbors-0/+21
Add method `String::retain` Behaves like `Vec::retain`, accepting a predicate `FnMut(char) -> bool` and reducing the string to only characters for which the predicate returns `true`.
2017-08-14Add method `String::retain`Murarth-0/+21
Behaves like `Vec::retain`, accepting a predicate `FnMut(char) -> bool` and reducing the string to only characters for which the predicate returns `true`.
2017-07-25std: Stabilize `utf8_error_error_len` featureAlex Crichton-1/+0
Stabilizes: * `Utf8Error::error_len` Closes #40494
2017-07-25std: Stabilize `str_checked_slicing` featureAlex Crichton-1/+0
Stabilized * `<str>::get` * `<str>::get_mut` * `<str>::get_unchecked` * `<str>::get_unchecked_mut` Closes #39932
2017-07-19Add Vec::drain_filterAlexis Beingessner-0/+168
2017-07-04Rollup merge of #43041 - andersk:dedup_by, r=alexcrichtonMark Simulacrum-0/+5
Document unintuitive argument order for Vec::dedup_by relation When trying to use `dedup_by` to merge some auxiliary information from removed elements into kept elements, I was surprised to observe that `vec.dedup_by(same_bucket)` calls `same_bucket(a, b)` where `b` appears before `a` in the vector, and discards `a` when true is returned. This argument order is probably a bug, but since it has already been stabilized, I guess we should document it as a feature and move on. (`Vec::dedup` also uses `==` with this unexpected argument order, but I figure that’s not important since `==` is expected to be symmetric with no side effects.)
2017-07-03Document unintuitive argument order for Vec::dedup_by relationAnders Kaseorg-0/+5
When trying to use dedup_by to merge some auxiliary information from removed elements into kept elements, I was surprised to observe that vec.dedup_by(same_bucket) calls same_bucket(a, b) where b appears before a in the vector, and discards a when true is returned. This argument order is probably a bug, but since it has already been stabilized, I guess we should document it as a feature and move on. (Vec::dedup also uses == with this unexpected argument order, but I figure that’s not important since == is expected to be symmetric with no side effects.) Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2017-07-01Delete deprecated & unstable range-specific `step_by`Scott McMurray-2/+1
Replacement: 41439 Deprecation: 42310 for 1.19 Fixes 41477
2017-06-24Improve sort tests and benchmarksStjepan Glavina-12/+38
2017-06-13Merge crate `collections` into `alloc`Murarth-0/+7074