about summary refs log tree commit diff
path: root/src/liballoc
AgeCommit message (Collapse)AuthorLines
2019-11-16Improve documentation of `Vec::split_off(...)`Mahmoud Al-Qudsi-4/+4
The previous ordering of the sentences kept switching between the return value and the value of `self` after execution, making it hard to follow. Additionally, as rendered in the browser, the period in "`Self`. `self`" was difficult to make out as being a sentence separator and not one code block.
2019-11-15Auto merge of #64432 - gnzlbg:simplify_truncate, r=alexcrichtonbors-22/+12
Make the semantics of Vec::truncate(N) consistent with slices. This commit simplifies the implementation of `Vec::truncate(N)` and makes its semantics identical to dropping the `[vec.len() - N..]` sub-slice tail of the vector, which is the same behavior as dropping a vector containing the same sub-slice. This changes two unspecified aspects of `Vec::truncate` behavior: * the drop order, from back-to-front to front-to-back, * the behavior of `Vec::truncate` on panics: if dropping one element of the tail panics, currently, `Vec::truncate` panics, but with this PR all other elements are still dropped, and if dropping a second element of the tail panics, with this PR, the program aborts. Programs can trivially observe both changes. For example ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=7bef575b83b06e82b3e3529e4edbcac7)): ```rust fn main() { struct Bomb(usize); impl Drop for Bomb { fn drop(&mut self) { panic!(format!("{}", self.0)); } } let mut v = vec![Bomb(0), Bomb(1)]; std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { v.truncate(0); })); assert_eq!(v.len(), 1); std::mem::forget(v); } ``` panics printing `1` today and succeeds. With this change, it panics printing `0` first (due to the drop order change), and then aborts with a double-panic printing `1`, just like dropping the `[Bomb(0), Bomb(1)]` slice does, or dropping `vec![Bomb(0), Bomb(1)]` does. This needs to go through a crater run. r? @SimonSapin
2019-11-14introduce benchmarks of HashSet operationsStein Somers-6/+2
2019-11-13Match VecDeque::extend to Vec::extendCharles Gleason-1/+16
2019-11-13Doc: Fix link to Exten in Vec::set_lenElichai Turkel-1/+1
2019-11-13Auto merge of #65637 - ssomers:master, r=scottmcmbors-11/+314
proposal for BTreeMap/Set min/max, #62924 - Which pair of names: #62924 lists the existing possibilities min/max, first/last, (EDIT) front/back, peek(/peek_back?). Iterators have next/next_back or next/last. I'm slightly in favour of first/last because min/max might suggest they search over the entire map, and front/back pretends they are only about position. - Return key only instead of pair like iterator does? - If not, then keep the _key_value suffix? ~~Also provide variant with mutable value? But there is no such variant for get_key_value.~~ - Look for and upgrade more usages of `.iter().next()` and such in the libraries? I only upgraded the ones I contributed myself, all very recently.
2019-11-11Auto merge of #65933 - crgl:vec-deque-truncate, r=alexcrichtonbors-4/+63
Use ptr::drop_in_place for VecDeque::truncate and VecDeque::clear This commit allows `VecDeque::truncate` to take advantage of its (largely) contiguous memory layout and is consistent with the change in #64432 for `Vec`. As with the change to `Vec::truncate`, this changes both: - the drop order, from back-to-front to front-to-back - the behavior when dropping an element panics For consistency, it also changes the behavior when dropping an element panics for `VecDeque::clear`. These changes in behavior can be observed. This example ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=d0b1f2edc123437a2f704cbe8d93d828)) ```rust use std::collections::VecDeque; fn main() { struct Bomb(usize); impl Drop for Bomb { fn drop(&mut self) { panic!(format!("{}", self.0)); } } let mut v = VecDeque::from(vec![Bomb(0), Bomb(1)]); std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { v.truncate(0); })); std::mem::forget(v); } ``` panics printing `1` today and succeeds. `v.clear()` panics printing `0` today and succeeds. With the change, `v.clear()`, `v.truncate(0)`, and dropping the `VecDeque` all panic printing `0` first and then abort with a double-panic printing `1`. The motivation for this was making `VecDeque::truncate` more efficient since it was used in the implementation of `VecDeque::clone_from` (#65069), but it also makes behavior more consistent within the `VecDeque` and with `Vec` if that change is accepted (this probably doesn't make sense to merge if not). This might need a crater run and an FCP as well.
2019-11-09Remove Layout::pad_to_align unwrapChristopher Durham-1/+1
2019-11-09Remove Layout::pad_to_unlign unwrapChristopher Durham-1/+1
2019-11-07Rollup merge of #66117 - olegnn:fixed_linked_list_marker, r=RalfJungYuki Okushi-3/+3
Fixed PhantomData markers in Arc and Rc Include owned internal structs in `PhantomData` markers in `Arc` (`PhantomData<T>` => `PhantomData<ArcInner<T>>`) and `Rc` (`PhantomData<T>` => `PhantomData<RcBox<T>>`).
2019-11-07Rollup merge of #66111 - RalfJung:from_raw_parts, r=CentrilYuki Okushi-1/+1
improve from_raw_parts docs Triggered by https://github.com/rust-lang/rfcs/pull/2806. Hopefully this helps clarify that joining slices across allocations is not possible in Rust currently. r? @Centril
2019-11-06gate rustc_on_unimplemented under rustc_attrsMazdak Farrokhzad-1/+1
2019-11-05Reverted PhantomData in LinkedList, fixed PhantomData markers in Rc and ArcOleg Nosov-4/+4
2019-11-05alloc: Add new_zeroed() versions like new_uninit().Emilio Cobos Álvarez-0/+85
MaybeUninit has both uninit() and zeroed(), it seems reasonable to have the same surface on Box/Rc/Arc. Needs tests.
2019-11-05LinkedList: PhantomData<Box<Node<T>>> => PhantomData<T>Oleg Nosov-3/+3
2019-11-05also edit String::from_raw_parts while we are at itRalf Jung-1/+1
2019-11-05Rollup merge of #66038 - jdxcode:char-len, r=alexcrichtonPietro Albini-2/+7
doc(str): show example of chars().count() under len() the docs are great at explaining that .len() isn't like in other languages but stops short of explaining how to get the character length.
2019-11-05Rollup merge of #65574 - tshepang:linked-list-disclaimer, r=CentrilPietro Albini-7/+7
docs: improve disclaimer regarding LinkedList
2019-11-02Merge branch 'master' into format-temporariesJon Gjengset-613/+1412
2019-11-01doc(str): show example of chars().count() under len()Jeff Dickey-2/+7
the docs are great at explaining that .len() isn't like in other languages but stops short of explaining how to get the character length. r? @steveklabnik
2019-11-01Update FFI exampleStephane Raux-4/+4
- Use meaningful names - Clarify comments - Fix C function declaration
2019-10-31Auto merge of #65091 - sekineh:into-iter-sorted, r=KodrAusbors-5/+204
Implement ordered/sorted iterators on BinaryHeap as per #59278 I've implemented the ordered version of iterator on BinaryHeap as per #59278. # Added methods: * `.into_iter_sorted()` * like `.into_iter()`; but returns elements in heap order * `.drain_sorted()` * like `.drain()`; but returns elements in heap order * It's a bit _lazy_; elements are removed on drop. (Edit: it’s similar to vec::Drain) For `DrainSorted` struct, I implemented `Drop` trait following @scottmcm 's [suggestion](https://github.com/rust-lang/rust/issues/59278#issuecomment-537306925) # ~TODO~ DONE * ~I think I need to add more tests other than doctest.~ # **Notes:** * we renamed `_ordered` to `_sorted`, because the latter is more common in rust libs. (as suggested by @KodrAus )
2019-10-31docs: improve disclaimer regarding LinkedListTshepang Lekhonkhobe-7/+7
2019-10-29Use truncate(0) in VecDeque clearCharles Gleason-1/+1
2019-10-29Add test for VecDeque truncateCharles Gleason-0/+35
2019-10-29Use ptr::drop_in_place in VecDeque truncateCharles Gleason-2/+25
2019-10-29Match docs for VecDeque truncate to Vec truncateCharles Gleason-1/+2
2019-10-28Rollup merge of #65887 - lzutao:doc-vec-get, r=rkruppeMazdak Farrokhzad-2/+4
doc: mention `get(_mut)` in Vec
2019-10-28doc: mention `get(_mut)` in VecLzu Tao-2/+4
2019-10-28Rollup merge of #65873 - lzutao:doc-vec-from-raw-parts, r=rkruppeMazdak Farrokhzad-1/+5
doc: explain why it is unsafe to construct Vec<u8> from Vec<u16>
2019-10-28Rollup merge of #64747 - ethanboxx:master, r=CentrilMazdak Farrokhzad-1/+0
Stabilize `Option::flatten` - PR: https://github.com/rust-lang/rust/pull/60256 - Tracking issue: https://github.com/rust-lang/rust/issues/60258 @elahn > I was trying to `flat_map()` and found `map().flatten()` does the trick. This has been on nightly for 4 months, can we stabilise it? @ethanboxx > @Centril Helped me get this merged. What is the stabilization process? @Centril > @ethanboxx I'd just file a PR to stabilize it and we'll ask T-libs to FCP. So here I am. I am was unsure what number to put in `since = "-"` so I copied what someone had done in a recent PR.
2019-10-27doc: explain why it is unsafe to construct Vec<u8> from Vec<u16>Lzu Tao-1/+5
Co-authored-by: Steve Klabnik <steve@steveklabnik.com>
2019-10-25Add {String,Vec}::into_raw_partsJake Goulding-0/+72
2019-10-25Use ManuallyDrop in examples for {Vec,String}::from_raw_partsJake Goulding-12/+14
2019-10-25Remove unneeded pointer castingJake Goulding-6/+6
2019-10-25fix doctestHideki Sekine-10/+4
2019-10-25Simplify .drain_sorted() and its doc.Hideki Sekine-45/+40
2019-10-25Remove unused `use`s.Hideki Sekine-4/+0
2019-10-25Add .into_iter_sorted() and .drain_sorted()Hideki Sekine-5/+219
* `.drain_sorted()` doc change suggested by @KodrAus
2019-10-23proposal for access to BTreeMap/BTreeSet first/last, #62924Stein Somers-11/+314
2019-10-23Rollup merge of #65144 - clarfon:moo, r=sfacklerMazdak Farrokhzad-0/+42
Add Cow::is_borrowed and Cow::is_owned Implements #65143.
2019-10-22Add Cow::is_borrowed and Cow::is_ownedClar Fon-0/+42
2019-10-22Apply clippy::needless_return suggestionsMateusz Mikuła-3/+3
2019-10-19Rollup merge of #65505 - RalfJung:rc, r=CentrilMazdak Farrokhzad-110/+137
Rc: value -> allocation See https://github.com/rust-lang/rust/issues/64484. This does not yet edit `Arc` as I first wanted to be sure we agree on the terminology the way it actually ends up. "value" as a term appears a lot in this file, and sometimes it refers to the value stored inside the `RcBox` while sometimes it refers to the `RcBox` itself. I tried to properly tease these apart but may have made some mistakes. The former should now always be called "inner value" and the latter "allocation". One area where I was very unsure of which terminology is dropping: the `value` field of the `RcBox` will get dropped *earlier* than the `RcBox` itself if there are weak references. I decided that "dropping the value stored in the allocation" refers to dropping the value field, while "destroying the allocation" refers to actually freeing its backing memory. r? @Centril
2019-10-19Rollup merge of #65226 - ssomers:master, r=blussMazdak Farrokhzad-121/+144
BTreeSet symmetric_difference & union optimized No scalability changes, but: - Grew the cmp_opt function (shared by symmetric_difference & union) into a MergeIter, with less memory overhead than the pairs of Peekable iterators now, speeding up ~20% on my machine (not so clear on Travis though, I actually switched it off there because it wasn't consistent about identical code). Mainly meant to improve readability by sharing code, though it does end up using more lines of code. Extending and reusing the MergeIter in btree_map might be better, but I'm not sure that's possible or desirable. This MergeIter probably pretends to be more generic than it is, yet doesn't declare to be an iterator because there's no need to, it's only there to help construct genuine iterators SymmetricDifference & Union. - Compact the code of #64820 by moving if/else into match guards. r? @bluss
2019-10-19do all the same edits with ArcRalf Jung-51/+65
2019-10-19some more Rc tweaksRalf Jung-10/+12
2019-10-19Stabilize `Option::flatten`Ethan Brierley-1/+0
2019-10-19the exampleis about drop, not (de)allocationRalf Jung-2/+2
2019-10-19Rollup merge of #65174 - SimonSapin:zero-box, r=alexcrichtonMazdak Farrokhzad-3/+33
Fix zero-size uninitialized boxes Requesting a zero-size allocation is not allowed, return a dangling pointer instead. CC https://github.com/rust-lang/rust/issues/63291#issuecomment-538692745