about summary refs log tree commit diff
path: root/src/liballoc
AgeCommit message (Collapse)AuthorLines
2018-06-02Rollup merge of #51312 - frewsxcv:clarify-hash-map-entry-get-mut, r=dtolnayMark Simulacrum-2/+15
Clarify the difference between get_mut and into_mut for OccupiedEntry The examples for both hash_map::OccupiedEntry::get_mut and hash_map::OccupiedEntry::into_mut were almost identical. This led to some confusion over the difference, namely why you would ever use get_mut when into_mut gives alonger lifetime. Reddit thread: https://www.reddit.com/r/rust/comments/8a5swr/why_does_hashmaps This commit adds two lines and a comment to the example, to show that the entry object can be re-used after calling get_mut. Closes https://github.com/rust-lang/rust/issues/49745
2018-06-02Rollup merge of #51306 - kennytm:impl-default-for-mut-str, r=SimonSapinMark Simulacrum-0/+1
impl Default for &mut str Rationale: There is already `impl Default for &mut [T]`. Note: This impl is insta-stable.
2018-06-02Copy changes from HashMap over to BTreeMap.Corey Farwell-2/+15
2018-06-02Rollup merge of #51147 - tmccombs:sliceindex, r=SimonSapinMark Simulacrum-2/+1
Stabilize SliceIndex trait. CC #35729 According to recommendations in https://github.com/rust-lang/rust/issues/35729#issuecomment-377784884
2018-06-03impl Default for &mut strkennytm-0/+1
2018-06-01incorporate changes from code reviewEmerentius-38/+46
further reduce unsafe fn calls reduce right drift assert! sufficient capacity
2018-06-01compacts join codeEmerentius-30/+14
2018-06-01add more join testsEmerentius-0/+22
old tests cover the new fast path of str joining already this adds tests for joining into Strings with long separators (>4 byte) and for joining into Vec<T>, T: Clone + !Copy. Vec<T: Copy> will be specialised when specialisation type inference bugs are fixed.
2018-06-01optimize joining and concatenation for slicesEmerentius-47/+113
for both Vec<T> and String - eliminates the boolean first flag in fn join() for String only - eliminates repeated bounds checks in join(), concat() - adds fast paths for small string separators up to a len of 4 bytes
2018-06-01Stabilize SliceIndex trait.Thayne McCombs-2/+1
Fixes #35729 According to recommendations in https://github.com/rust-lang/rust/issues/35729#issuecomment-377784884
2018-05-31Update `Arc` and `Rc` to use `NonNull::cast` to cast the inner pointersJeremy Fitzhardinge-17/+6
This avoids an `unsafe` block in each case.
2018-05-31Implement `downcast` for `Arc<Any + Send + Sync>`Jeremy Fitzhardinge-0/+64
We only need to implement it for `Any + Send + Sync` because in practice that's the only useful combination for `Arc` and `Any`. Implementation for #44608 under the `rc_downcast` feature.
2018-05-30Pass a `Layout` to `oom`Mike Hommey-82/+91
As discussed in https://github.com/rust-lang/rust/issues/49668#issuecomment-384893456 and subsequent, there are use-cases where the OOM handler needs to know the size of the allocation that failed. The alignment might also be a cause for allocation failure, so providing it as well can be useful.
2018-05-26Auto merge of #51082 - kennytm:rollup, r=kennytmbors-2/+4
Rollup of 11 pull requests Successful merges: - #50987 (Underline multiple suggested replacements in the same line) - #51014 (Add documentation about env! second argument) - #51034 (Remove unused lowering field and method) - #51047 (Use AllFacts from polonius-engine) - #51048 (Add more missing examples for Formatter) - #51056 (Mention and use `Once::new` instead of `ONCE_INIT`) - #51059 (What does an expression look like, that consists only of special characters?) - #51065 (Update nomicon link in transmute docs) - #51067 (Add inner links in documentation) - #51070 (Fail typecheck if we encounter a bogus break) - #51073 (Rename TokenStream::empty to TokenStream::new) Failed merges:
2018-05-26Rollup merge of #51067 - mcarton:patch-1, r=steveklabnikkennytm-2/+4
Add inner links in documentation From [this SO question](https://stackoverflow.com/q/50518757/2733851) it looks like this page isn't really clear. I personally do think this page is quite clear, the only think I could think of was adding some references.
2018-05-26Auto merge of #51041 - alexcrichton:better-unwind, r=nikomatsakisbors-0/+1
std: Ensure OOM is classified as `nounwind` OOM can't unwind today, and historically it's been optimized as if it can't unwind. This accidentally regressed with recent changes to the OOM handler, so this commit adds in a codegen test to assert that everything gets optimized away after the OOM function is approrpiately classified as nounwind Closes #50925
2018-05-25Auto merge of #51033 - coryshrmn:master, r=dtolnaybors-11/+11
stabilize RangeBounds collections_range #30877 The FCP for #30877 closed last month, with the decision to: 1. move from `collections::range::RangeArgument` to `ops::RangeBounds`, and 2. rename `start()` and `end()` to `start_bounds()` and `end_bounds()`. Simon Sapin already moved it to `ops::RangeBounds` in #49163. I renamed the functions, and removed the old `collections::range::RangeArgument` alias. This is my first Rust PR, please let me know if I can improve anything. This passes all tests for me, except the `clippy` tool (which uses `RangeArgument::start()`). I considered deprecating `start()` and `end()` instead of removing them, but the contribution guidelines indicate we can break `clippy` temporarily. I thought it was best to remove the functions, since we're worried about name collisions with `Range::start` and `end`. Closes #30877.
2018-05-25Add inner links in documentationMartin Carton-2/+4
From [this SO question](https://stackoverflow.com/q/50518757/2733851) it looks like this page isn't really clear. I personally do think this page is quite clear, the only think I could think of was adding some references.
2018-05-24std: Ensure OOM is classified as `nounwind`Alex Crichton-0/+1
OOM can't unwind today, and historically it's been optimized as if it can't unwind. This accidentally regressed with recent changes to the OOM handler, so this commit adds in a codegen test to assert that everything gets optimized away after the OOM function is approrpiately classified as nounwind Closes #50925
2018-05-24stabilize RangeBounds collections_range #30877Cory Sherman-11/+11
rename RangeBounds::start() -> start_bound() rename RangeBounds::end() -> end_bound()
2018-05-22Make `Unpin` safe to implementTaylor Cramer-1/+1
2018-05-23Rollup merge of #50945 - stjepang:stabilize-from-ref, r=SimonSapinkennytm-2/+2
Stabilize feature from_ref Function `from_ref_mut` is now renamed to `from_mut`, as discussed in #45703. Closes #45703. r? @SimonSapin
2018-05-21Auto merge of #49283 - varkor:combining-chars-escape_debug, r=SimonSapinbors-1/+17
Escape combining characters in char::Debug Although combining characters are technically printable, they make little sense to print on their own with `Debug`: it'd be better to escape them like non-printable characters. This is a breaking change, but I imagine the fact `escape_debug` is rare and almost certainly primarily used for debugging that this is an acceptable change. Resolves #41922. r? @alexcrichton cc @clarcharr
2018-05-21Avoid counting characters and add explanatory comment to testvarkor-1/+13
2018-05-21Only escape extended grapheme characters in the first positionvarkor-2/+5
2018-05-21Make {char, str}::escape_debug and impl Debug for {char, str} consistentvarkor-0/+1
2018-05-21Stabilize feature from_refStjepan Glavina-2/+2
2018-05-21Auto merge of #50739 - gnzlbg:vec_reserve, r=sfacklerbors-2/+2
Switch Vec from doubling size on growth to using RawVec's reserve On growth, Vec does not require to exactly double its size for correctness, like, for example, VecDeque does. Using reserve instead better expresses this intent. It also allows to reuse Excess capacity on growth and for better growth-policies to be provided by RawVec. r? @sfackler
2018-05-17Stabilise inclusive_range_methodsvarkor-1/+0
2018-05-17Auto merge of #50629 - Mark-Simulacrum:stage-step, r=alexcrichtonbors-76/+6
Switch to bootstrapping from 1.27 It's possible the Float trait could be removed from core, but I couldn't tell whether it was intended to be removed or not. @SimonSapin may be able to comment more here; we can presumably also do that in a follow up PR as this one is already quite large.
2018-05-17Switch to 1.26 bootstrap compilerMark Simulacrum-76/+6
2018-05-17Rename trans to codegen everywhere.Irina Popa-1/+1
2018-05-17Rollup merge of #50170 - burtonageo:more_cow_from, r=alexcrichtonkennytm-0/+15
Implement From for more types on Cow This is basically https://github.com/rust-lang/rust/pull/48191, except that it should be implemented in a way that doesn't break third party crates.
2018-05-16Stabilize num::NonZeroU*Simon Sapin-1/+0
Tracking issue: https://github.com/rust-lang/rust/issues/49137
2018-05-14Switch Vec from doubling size on growth to using RawVec's reservegnzlbg-2/+2
On growth, Vec does not require to exactly double its size for correctness, like, for example, VecDeque does. Using reserve instead better expresses this intent. It also allows to reuse Excess capacity on growth and for better growth-policies to be provided by RawVec.
2018-05-12Auto merge of #50352 - porglezomp:btree-no-empty-alloc, r=Gankrobors-31/+128
Don't allocate when creating an empty BTree Following the discussion in #50266, this adds a static instance of `LeafNode` that empty BTrees point to, and then replaces it on `insert`, `append`, and `entry`. This avoids allocating for empty maps. Fixes #50266 r? @Gankro
2018-05-10Skip a memory-hungry test that OOMsAlex Crichton-0/+1
Attempting to fix https://travis-ci.org/rust-lang/rust/jobs/377407894 via some selective ignoring tests
2018-05-10Rollup merge of #50591 - glandium:cleanup, r=dtolnayAlex Crichton-56/+57
Restore RawVec::reserve* documentation When the RawVec::try_reserve* methods were added, they took the place of the ::reserve* methods in the source file, and new ::reserve* methods wrapping the new try_reserve* methods were created. But the documentation didn't move along, such that: - reserve_* methods are barely documented. - try_reserve_* methods have unmodified documentation from reserve_*, such that their documentation indicate they are panicking/aborting. This moves the documentation back to the right methods, with a placeholder documentation for the try_reserve* methods.
2018-05-10Rollup merge of #50588 - ExpHP:i-can-see-my-house-from-here, r=frewsxcvAlex Crichton-4/+4
Move "See also" disambiguation links for primitive types to top Closes #50384. <details> <summary>Images</summary> ![rust-slice](https://user-images.githubusercontent.com/1411280/39843148-caa41c3e-53b7-11e8-8123-b57c25a4d9e0.png) ![rust-isize](https://user-images.githubusercontent.com/1411280/39843146-ca94b384-53b7-11e8-85f3-3f5e5d353a05.png) </details> r? @steveklabnik
2018-05-10Rollup merge of #50575 - alexcrichton:faster-drain-drop, r=sfacklerAlex Crichton-3/+5
std: Avoid `ptr::copy` if unnecessary in `vec::Drain` This commit is spawned out of a performance regression investigation in #50496. In tracking down this regression it turned out that the `expand_statements` function in the compiler was taking quite a long time. Further investigation showed two key properties: * The function was "fast" on glibc 2.24 and slow on glibc 2.23 * The hottest function was memmove from glibc Combined together it looked like glibc gained an optimization to the memmove function in 2.24. Ideally we don't want to rely on this optimization, so I wanted to dig further to see what was happening. The hottest part of `expand_statements` was `Drop for Drain` in the call to `splice` where we insert new statements into the original vector. This *should* be a cheap operation because we're draining and replacing iterators of the exact same length, but under the hood memmove was being called a lot, causing a slowdown on glibc 2.23. It turns out that at least one of the optimizations in glibc 2.24 was that `memmove` where the src/dst are equal becomes much faster. [This program][prog] executes in ~2.5s against glibc 2.23 and ~0.3s against glibc 2.24, exhibiting how glibc 2.24 is optimizing `memmove` if the src/dst are equal. And all that brings us to what this commit itself is doing. The change here is purely to `Drop for Drain` to avoid the call to `ptr::copy` if the region being copied doesn't actually need to be copied. For normal usage of just `Drain` itself this check isn't really necessary, but because `Splice` internally contains `Drain` this provides a nice speed boost on glibc 2.23. Overall this should fix the regression seen in #50496 on glibc 2.23 and also fix the regression on Windows where `memmove` looks to not have this optimization. Note that the way `splice` was called in `expand_statements` would cause a quadratic number of elements to be copied via `memmove` which is likely why the tuple-stress benchmark showed such a severe regression. Closes #50496 [prog]: https://gist.github.com/alexcrichton/c05bc51c6771bba5ae5b57561a6c1cd3
2018-05-10Rollup merge of #50010 - ExpHP:slice-bounds, r=alexcrichtonAlex Crichton-134/+355
Give SliceIndex impls a test suite of girth befitting the implementation (and fix a UTF8 boundary check) So one day I was writing something in my codebase that basically amounted to `impl SliceIndex for (Bound<usize>, Bound<usize>)`, and I said to myself: *Boy, gee, golly! I never realized bounds checking was so tricky!* At some point when I had around 60 lines of tests for it, I decided to go see how the standard library does it to see if I missed any edge cases. ...That's when I discovered that libcore only had about 40 lines of tests for slicing altogether, and none of them even used `..=`. --- This PR includes: * **Literally the first appearance of the word `get_unchecked_mut` in any directory named `test` or `tests`.** * Likewise the first appearance of `get_mut` used with _any type of range argument_ in these directories. * Tests for the panics on overflow with `..=`. * I wanted to test on `[(); usize::MAX]` as well but that takes linear time in debug mode </3 * A horrible and ugly test-generating macro for the `should_panic` tests that increases the DRYness by a single order of magnitude (which IMO wasn't enough, but I didn't want to go any further and risk making the tests inaccessible to next guy). * Same stuff for str! * Actually, the existing `str` tests were pretty good. I just helped filled in the holes. * [A fix for the bug it caught](https://github.com/rust-lang/rust/issues/50002). (only one ~~sadly~~)
2018-05-10Restore RawVec::reserve* documentationMike Hommey-56/+57
When the RawVec::try_reserve* methods were added, they took the place of the ::reserve* methods in the source file, and new ::reserve* methods wrapping the new try_reserve* methods were created. But the documentation didn't move along, such that: - reserve_* methods are barely documented. - try_reserve_* methods have unmodified documentation from reserve_*, such that their documentation indicate they are panicking/aborting. This moves the documentation back to the right methods, with a placeholder documentation for the try_reserve* methods.
2018-05-09move See also links to topMichael Lamparski-4/+4
2018-05-09std: Avoid `ptr::copy` if unnecessary in `vec::Drain`Alex Crichton-3/+5
This commit is spawned out of a performance regression investigation in #50496. In tracking down this regression it turned out that the `expand_statements` function in the compiler was taking quite a long time. Further investigation showed two key properties: * The function was "fast" on glibc 2.24 and slow on glibc 2.23 * The hottest function was memmove from glibc Combined together it looked like glibc gained an optimization to the memmove function in 2.24. Ideally we don't want to rely on this optimization, so I wanted to dig further to see what was happening. The hottest part of `expand_statements` was `Drop for Drain` in the call to `splice` where we insert new statements into the original vector. This *should* be a cheap operation because we're draining and replacing iterators of the exact same length, but under the hood memmove was being called a lot, causing a slowdown on glibc 2.23. It turns out that at least one of the optimizations in glibc 2.24 was that `memmove` where the src/dst are equal becomes much faster. [This program][prog] executes in ~2.5s against glibc 2.23 and ~0.3s against glibc 2.24, exhibiting how glibc 2.24 is optimizing `memmove` if the src/dst are equal. And all that brings us to what this commit itself is doing. The change here is purely to `Drop for Drain` to avoid the call to `ptr::copy` if the region being copied doesn't actually need to be copied. For normal usage of just `Drain` itself this check isn't really necessary, but because `Splice` internally contains `Drain` this provides a nice speed boost on glibc 2.23. Overall this should fix the regression seen in #50496 on glibc 2.23 and also fix the regression on Windows where `memmove` looks to not have this optimization. Note that the way `splice` was called in `expand_statements` would cause a quadratic number of elements to be copied via `memmove` which is likely why the tuple-stress benchmark showed such a severe regression. Closes #50496 [prog]: https://gist.github.com/alexcrichton/c05bc51c6771bba5ae5b57561a6c1cd3
2018-05-09Rollup merge of #50527 - glandium:cleanup, r=sfacklerkennytm-1/+1
Cleanup a `use` in a raw_vec test `allocator` is deprecated in favor of `alloc`, and `Alloc` is already imported through `super::*`.
2018-05-09Rollup merge of #50511 - Manishearth:must-use, r=QuietMisdreavuskennytm-2/+4
Add some explanations for #[must_use] `#[must_use]` can be given a string argument which is shown whilst warning for things. We should add a string argument to most of the user-exposed ones. I added these for everything but the operators, mostly because I'm not sure what to write there or if we need anything there.
2018-05-09Rollup merge of #50460 - F001:const_string, r=kennytmkennytm-1/+3
Make `String::new()` const Following the steps of https://github.com/rust-lang/rust/pull/50233 , make `String::new()` a `const fn`.
2018-05-09Update features to 1.28.0George Burton-2/+2
2018-05-08Make an ensure_root_is_owned method to reduce duplicationC Jones-15/+10
Also remove some unnecessary debug_assert! when creating the shared root, since the root should be stored in the rodata and thus be impossible to accidentally modify.
2018-05-08Auto merge of #50497 - RalfJung:pinmut, r=withoutboatsbors-3/+3
Rename Pin to PinMut, and some more breaking changes As discussed at [1] ยง3 and [2] and [3], a formal look at pinning requires considering a distinguished "shared pinned" mode/typestate. Given that, it seems desirable to at least eventually actually expose that typestate as a reference type. This renames Pin to PinMut, freeing the name Pin in case we want to use it for a shared pinned reference later on. [1] https://www.ralfj.de/blog/2018/04/10/safe-intrusive-collections-with-pinning.html [2] https://github.com/rust-lang/rfcs/pull/2349#issuecomment-379250361 [3] https://github.com/rust-lang/rust/issues/49150#issuecomment-380488275 Cc @withoutboats