about summary refs log tree commit diff
path: root/src/liballoc
AgeCommit message (Collapse)AuthorLines
2019-08-22Fix formatting.Tomasz Różański-1/+1
2019-08-22Fix a typo.Tomasz Różański-1/+1
2019-08-19Rollup merge of #63252 - nrc:arc-doc, r=alexcrichtonMazdak Farrokhzad-4/+0
Remove recommendation about idiomatic syntax for Arc::clone I believe we should not make this recommendation. I don't want to argue that `Arc::clone` is less idiomatic than `arc.clone`, but that the choice is not clear cut and that we should not be making this kind of call in the docs. The `.clone()` form has advantages too: it is more succinct, it is more likely to be understood by beginners, and it is more uniform with other `clone` calls, indeed with most other method calls. Whichever approach is better, I think that this discussion belongs in a style guide or textbook, rather than the library docs. We don't talk much about idiomatic code in the docs, this place is pretty exceptional. The recommendation is also not followed in this repo. It is hard to figure out how many calls there are of the `.clone()` form, but there are 1550 uses of `Arc` and only 65 uses of `Arc::clone`. The recommendation has existed for over two years. The recommendation was added in https://github.com/rust-lang/rust/pull/42137, as a result of https://github.com/rust-lang/rfcs/pull/1954. However, note that that RFC was closed because it was not necessary to change the docs (the original RFC proposed a new function instead). So I don't think an RFC is necessary here (and I'm not trying to re-litigate the discussion on that RFC (which favoured `Arc::clone` as idiomatic) in any case). cc @nical (who added the docs in the first place; sorry :-) ) r? @alexcrichton (or someone else on @rust-lang/libs )
2019-08-18Auto merge of #63045 - Rosto75:master, r=jonas-schievinkbors-43/+43
Change the placement of two functions. Right now, the order is as follows: `pop_front()` `push_front()` `push_back()` `pop_back()` `swap_remove_back()` `swap_remove_front()` I believe it would be more natural, and easier to follow, if we place `pop_back()` right after the `pop_front()`, and `swap_remove_back()` after the `swap_remove_front()` like this: `pop_front()` `pop_back()` `push_front()` `push_back()` `swap_remove_front()` `swap_remove_back()` The rest of the documentation (at least in this module) adheres to the same logic, where the 'front' function always precedes its 'back' equivalent.
2019-08-17Rollup merge of #62451 - SimonSapin:new_uninit, r=RalfJungMazdak Farrokhzad-10/+497
Add APIs for uninitialized Box, Rc, and Arc. (Plus get_mut_unchecked) Assigning `MaybeUninit::<Foo>::uninit()` to a local variable is usually free, even when `size_of::<Foo>()` is large. However, passing it for example to `Arc::new` [causes at least one copy](https://youtu.be/F1AquroPfcI?t=4116) (from the stack to the newly allocated heap memory) even though there is no meaningful data. It is theoretically possible that a Sufficiently Advanced Compiler could optimize this copy away, but this is [reportedly unlikely to happen soon in LLVM](https://youtu.be/F1AquroPfcI?t=5431). This PR proposes two sets of features: * Constructors for containers (`Box`, `Rc`, `Arc`) of `MaybeUninit<T>` or `[MaybeUninit<T>]` that do not initialized the data, and unsafe conversions to the known-initialized types (without `MaybeUninit`). The constructors are guaranteed not to make unnecessary copies. * On `Rc` and `Arc`, an unsafe `get_mut_unchecked` method that provides `&mut T` access without checking the reference count. `Arc::get_mut` involves multiple atomic operations whose cost can be non-trivial. `Rc::get_mut` is less costly, but we add `Rc::get_mut_unchecked` anyway for symmetry with `Arc`. These can be useful independently, but they will presumably be typical when the new constructors of `Rc` and `Arc` are used. An alternative with a safe API would be to introduce `UniqueRc` and `UniqueArc` types that have the same memory layout as `Rc` and `Arc` (and so zero-cost conversion to them) but are guaranteed to have only one reference. But introducing entire new types feels “heavier” than new constructors on existing types, and initialization of `MaybeUninit<T>` typically requires unsafe code anyway. Summary of new APIs (all unstable in this PR): ```rust impl<T> Box<T> { pub fn new_uninit() -> Box<MaybeUninit<T>> {…} } impl<T> Box<MaybeUninit<T>> { pub unsafe fn assume_init(self) -> Box<T> {…} } impl<T> Box<[T]> { pub fn new_uninit_slice(len: usize) -> Box<[MaybeUninit<T>]> {…} } impl<T> Box<[MaybeUninit<T>]> { pub unsafe fn assume_init(self) -> Box<[T]> {…} } impl<T> Rc<T> { pub fn new_uninit() -> Rc<MaybeUninit<T>> {…} } impl<T> Rc<MaybeUninit<T>> { pub unsafe fn assume_init(self) -> Rc<T> {…} } impl<T> Rc<[T]> { pub fn new_uninit_slice(len: usize) -> Rc<[MaybeUninit<T>]> {…} } impl<T> Rc<[MaybeUninit<T>]> { pub unsafe fn assume_init(self) -> Rc<[T]> {…} } impl<T> Arc<T> { pub fn new_uninit() -> Arc<MaybeUninit<T>> {…} } impl<T> Arc<MaybeUninit<T>> { pub unsafe fn assume_init(self) -> Arc<T> {…} } impl<T> Arc<[T]> { pub fn new_uninit_slice(len: usize) -> Arc<[MaybeUninit<T>]> {…} } impl<T> Arc<[MaybeUninit<T>]> { pub unsafe fn assume_init(self) -> Arc<[T]> {…} } impl<T: ?Sized> Rc<T> { pub unsafe fn get_mut_unchecked(this: &mut Self) -> &mut T {…} } impl<T: ?Sized> Arc<T> { pub unsafe fn get_mut_unchecked(this: &mut Self) -> &mut T {…} } ```
2019-08-17Rename private helper method allocate_for_unsized to allocate_for_layoutSimon Sapin-10/+10
2019-08-17Doc nitsSimon Sapin-14/+14
Co-Authored-By: Ralf Jung <post@ralfj.de>
2019-08-16Rollup merge of #63613 - petrochenkov:stdhyg, r=alexcrichtonMazdak Farrokhzad-1/+1
Hygienize use of built-in macros in the standard library Same as https://github.com/rust-lang/rust/pull/61629, but for built-in macros. Closes https://github.com/rust-lang/rust/issues/48781 r? @alexcrichton
2019-08-16Add the Layout of the failed allocation to TryReserveError::AllocErrorSimon Sapin-40/+46
… and add a separately-unstable field to force non-exhaustive matching (`#[non_exhaustive]` is no implemented yet on enum variants) so that we have the option to later expose the allocator’s error value. CC https://github.com/rust-lang/wg-allocators/issues/23
2019-08-16Rename CollectionAllocError to TryReserveErrorSimon Sapin-36/+36
2019-08-16Relax the safety condition for get_mut_uncheckedSimon Sapin-4/+8
2019-08-16Reuse more internal Rc and Arc methodsSimon Sapin-70/+14
2019-08-16Add a comment on the usage of Layout::new::<RcBox<()>>()Simon Sapin-0/+4
2019-08-16Add tracking issue numbersSimon Sapin-14/+14
2019-08-16Use ManuallyDrop instead of mem::forgetSimon Sapin-12/+4
Per https://github.com/rust-lang/rust/pull/62451#discussion_r303197278
2019-08-16Use `alloc::Global` in `Box::new_uninit`Simon Sapin-4/+6
2019-08-16Fix intra-rustdoc linksSimon Sapin-2/+14
2019-08-16Move constructors of boxed/rc’ed slices to matching `impl` blocksSimon Sapin-100/+106
2019-08-16Add new_uninit_slice and assume_init on Box, Rc, and Arc of [T]Simon Sapin-14/+256
2019-08-16Add new_uninit and assume_init on Box, Rc, and ArcSimon Sapin-0/+223
2019-08-16Add Rc::get_mut_unchecked, Arc::get_mut_uncheckedSimon Sapin-2/+60
2019-08-15Hygienize use of built-in macros in the standard libraryVadim Petrochenkov-1/+1
2019-08-14Auto merge of #63534 - Mark-Simulacrum:stage0-bump, r=Centrilbors-6/+6
Bump to 1.39 r? @Centril
2019-08-14Handle cfg(bootstrap) throughoutMark Rousskov-6/+6
2019-08-12Apply suggestions from code reviewObserver42-2/+2
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-08-12Document From trait for BinaryHeapObserver42-0/+3
2019-08-10Rollup merge of #63350 - iluuu1994:use-associated-type-bounds, r=CentrilMazdak Farrokhzad-10/+14
Use associated_type_bounds where applicable - closes #61738
2019-08-09Rollup merge of #63407 - RalfJung:miri-test-sizes, r=CentrilMazdak Farrokhzad-0/+27
reduce some test sizes in Miri
2019-08-09reduce some test sizes in MiriRalf Jung-0/+27
2019-08-09Add missing #![feature(associated_type_bounds)]Ilija Tovilo-0/+1
2019-08-09Merge pull request #1 from rust-lang/masterSayan Nandan-2519/+4279
Merge recent changes into master
2019-08-09Improve tests for liballoc/btree/setSayan Nandan-2/+2
2019-08-08Use associated_type_bounds where applicable - closes #61738Ilija Tovilo-10/+13
2019-08-08Rollup merge of #63261 - RalfJung:rand, r=nikomatsakisMazdak Farrokhzad-6/+6
bump rand in libcore/liballoc test suites This pulls in the fix for https://github.com/rust-random/rand/issues/779, which trips Miri when running these test suites. `SmallRng` (formerly used by libcore) is no longer built by default, it needs a feature gate. I opted to switch to `StdRng` instead. Or should I enable the feature gate?
2019-08-05Add implementations for converting boxed slices into boxed arraysJake Goulding-6/+94
This mirrors the implementations of reference slices into arrays.
2019-08-04bump rand to fix Miri failuresRalf Jung-6/+6
2019-08-04Remove recommendation about idiomatic syntax for Arc::CloneNick Cameron-4/+0
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2019-08-02Remove some more `cfg(test)`sVadim Petrochenkov-4/+0
2019-08-02liballoc: Unconfigure tests during normal buildVadim Petrochenkov-1681/+1672
Remove additional libcore-like restrictions from liballoc, turns out the testing works ok if the tests are a part of liballoc itself.
2019-07-30Rollup merge of #63095 - Centril:incomplete-features-lint, r=varkorMazdak Farrokhzad-0/+1
Turn `INCOMPLETE_FEATURES` into lint We do this because it is annoying to see the warning when building rustc and because this is better from a "separation of concerns" POV. The drawback to this change is that this will respect `--cap-lints`. Also note that this is not a buffered lint so if there are fatal parser errors then the lint will not trigger. r? @varkor
2019-07-30Rollup merge of #62469 - czipperz:liballoc-add-doc-links, r=GuillaumeGomezMazdak Farrokhzad-13/+19
Add doc links to liballoc crate page
2019-07-30Allow 'incomplete_features' in libcore/alloc.Mazdak Farrokhzad-0/+1
2019-07-29comments from @lzutaoMaximilian Roos-1/+1
2019-07-29impl Debug for CharsMaximilian Roos-0/+10
2019-07-28Deny `unused_lifetimes` through rustbuildVadim Petrochenkov-0/+2
2019-07-28Remove lint annotations in specific crates that are already enforced by ↵Vadim Petrochenkov-3/+0
rustbuild Remove some random unnecessary lint `allow`s
2019-07-28Rollup merge of #63061 - Centril:constantly-improving, r=scottmcmMazdak Farrokhzad-59/+39
In which we constantly improve the Vec(Deque) array PartialEq impls Use the same approach as in https://github.com/rust-lang/rust/pull/62435 as sanctioned by https://github.com/rust-lang/rust/issues/61415#issuecomment-504155110. r? @scottmcm
2019-07-28Rollup merge of #62806 - mati865:clippy, r=TimNNMazdak Farrokhzad-9/+9
Fix few Clippy warnings
2019-07-28Use const generics for some VecDeque impls.Mazdak Farrokhzad-26/+14
2019-07-28Use const generics for some Vec/CCow impls.Mazdak Farrokhzad-33/+25