about summary refs log tree commit diff
path: root/src/liballoc
AgeCommit message (Collapse)AuthorLines
2019-12-03Auto merge of #66256 - CAD97:patch-2, r=RalfJungbors-2/+2
Layout::pad_to_align is infallible As per [this comment](https://github.com/rust-lang/rust/issues/55724#issuecomment-441421651) (cc @glandium). > Per https://github.com/rust-lang/rust/blob/eb981a1/src/libcore/alloc.rs#L63-L65, `layout.size()` is always <= `usize::MAX - (layout.align() - 1)`. > > Which means: > > * The maximum value `layout.size()` can have is already aligned for `layout.align()` (`layout.align()` being a power of two, `usize::MAX - (layout.align() - 1)` is a multiple of `layout.align()`) > * Incidentally, any value smaller than that maximum value will align at most to that maximum value. > > IOW, `pad_to_align` can not return `Err(LayoutErr)`, except for the layout not respecting its invariants, but we shouldn't care about that. This PR makes `pad_to_align` return `Layout` directly, representing the fact that it cannot fail.
2019-12-01Rollup merge of #66890 - dtolnay:fmt4, r=Dylan-DPCMazdak Farrokhzad-401/+373
Format liballoc with rustfmt Same strategy as #66691 -- as with my previous formatting PRs, I am avoiding causing merge conflicts in other PRs by only touches those files that are not involved in any currently open PR. Files that appear in new PRs between when this PR is opened and when it makes it to the top of the bors queue will be reverted from this PR. The list of files involved in open PRs is determined by querying GitHub's GraphQL API [with this script](https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8). With the list of files from the script in outstanding_files, the relevant commands were: ``` $ find src/liballoc -name '*.rs' \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ rg liballoc outstanding_files | xargs git checkout -- ``` To confirm no funny business: ``` $ git checkout $THIS_COMMIT^ $ git show --pretty= --name-only $THIS_COMMIT \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ git diff $THIS_COMMIT # there should be no difference ``` r? @Dylan-DPC
2019-12-01Rollup merge of #66662 - RalfJung:miri-test-liballoc, r=dtolnayMazdak Farrokhzad-14/+24
Miri: run panic-catching tests in liballoc I also converted two tests from using `thread::spawn(...).join()` just for catching panics, to `catch_panic`, so that Miri can run them.
2019-11-30Rollup merge of #66759 - CAD97:patch-3, r=KodrAusMazdak Farrokhzad-0/+3
impl TrustedLen for vec::Drain The iterator methods just forward to `slice::Iter`, which is `TrustedLen`. This can probably be applied to other `Drain` structs as well.
2019-11-29Format liballoc with rustfmtDavid Tolnay-401/+373
2019-11-27Rollup merge of #66798 - bwignall:typo, r=varkorTyler Mandry-3/+3
Fix spelling typos Should be non-semantic. Uses https://en.wikipedia.org/wiki/Wikipedia:Lists_of_common_misspellings/For_machines to find likely typos.
2019-11-27Rollup merge of #66744 - chrisduerr:master, r=Dylan-DPCTyler Mandry-0/+2
Fix shrink_to panic documentation While the potential for panicking is already documented for the `Vec::shrink_to` method, it is not clearly labeled with the usual `# Panics` heading. r? @steveklabnik
2019-11-26Fix spelling typosBrian Wignall-3/+3
2019-11-26Rollup merge of #66128 - emilio:new-zeroed, r=SimonSapinTyler Mandry-0/+85
alloc: Add new_zeroed() versions like new_uninit(). MaybeUninit has both uninit() and zeroed(), it seems reasonable to have the same surface on Box/Rc/Arc. Needs tests. cc #63291
2019-11-25impl TrustedLen for vec::DrainChristopher Durham-0/+3
2019-11-25Fix shrink_to panic documentationChristian Duerr-0/+2
While the potential for panicking is already documented for the `Vec::shrink_to` method, it is not clearly labeled with the usual `# Panics` heading.
2019-11-24Auto merge of #66393 - ssomers:hash_benches, r=dtolnaybors-6/+2
introduce benchmarks of HashSet operations To avoid goofs such as corrected by #66280, I added benchmarks of binary HashSet operations. Due to the fact x.py keeps recompiling the whole shebang (or at least a big part of it) whenever you touch the test code, and because piling up all tests in one file does not strike me as future proof, I tried moving the hash benches to the separate place they are for liballoc/collections/btree. But it turns out that, in a cleaned checkout, x.py still recompiles the whole shebang whenever you touch the test code (PS or when you add or delete any irrelevant file). So I'm not going to add more tests, and I doubt others will, and these tests have proven their point already, so this PR is kind of pointless
2019-11-24Rollup merge of #64856 - jonhoo:format-temporaries, r=sfacklerMazdak Farrokhzad-1/+4
Scope format! temporaries This places the temporaries that `format!` generates to refer to its arguments (through `&dyn Trait`) in a short-lived scope surrounding just the invocation of `format!`. This enables `format!` to be used in generators without the temporaries preventing the generator from being `Send` (due to `dyn Trait` not being `Sync`). See rust-lang/rust#64477 for details.
2019-11-23enable more panic-catching tests in MiriRalf Jung-4/+15
2019-11-22enable panic-catching tests in MiriRalf Jung-3/+6
2019-11-22use catch_panic instead of thread::spawn to catch panicsRalf Jung-8/+5
2019-11-22enable panic-catching tests in MiriRalf Jung-4/+3
2019-11-16Revise the text of `vec::split_off()` per review in #65739Mahmoud Al-Qudsi-4/+3
Remove the incorrect usage of "copy" as the trait is not called.
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-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-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