about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2023-07-14Auto merge of #113113 - Amanieu:box-vec-zst, r=Mark-Simulacrumbors-25/+49
Eliminate ZST allocations in `Box` and `Vec` This PR fixes 2 issues with `Box` and `RawVec` related to ZST allocations. Specifically, the `Allocator` trait requires that: - If you allocate a zero-sized layout then you must later deallocate it, otherwise the allocator may leak memory. - You cannot pass a ZST pointer to the allocator that you haven't previously allocated. These restrictions exist because an allocator implementation is allowed to allocate non-zero amounts of memory for a zero-sized allocation. For example, `malloc` in libc does this. Currently, ZSTs are handled differently in `Box` and `Vec`: - `Vec` never allocates when `T` is a ZST or if the vector capacity is 0. - `Box` just blindly passes everything on to the allocator, including ZSTs. This causes problems due to the free conversions between `Box<[T]>` and `Vec<T>`, specifically that ZST allocations could get leaked or a dangling pointer could be passed to `deallocate`. This PR fixes this by changing `Box` to not allocate for zero-sized values and slices. It also fixes a bug in `RawVec::shrink` where shrinking to a size of zero did not actually free the backing memory.
2023-07-13Fix VecDeque's rotate_left and rotate_right panic testsPedro Lobo-2/+2
2023-07-13Rename VecDeque's rotate_left and rotate_right parametersPedro Lobo-23/+23
2023-07-13Eliminate ZST allocations in `Box` and `Vec`Amanieu d'Antras-25/+49
2023-07-12Flip cfg's for bootstrap bumpMark Rousskov-21/+0
2023-07-12Replace version placeholder to 1.72Mark Rousskov-1/+1
2023-07-08mark as stableTristan Guichaoua-1/+1
2023-07-08impl `From<&[T; N]>` for `Cow<[T]>`Tristan Guichaoua-0/+13
2023-07-04Revert "alloc: Allow comparing `Box`s over different allocators"Trevor Gross-26/+9
This reverts commit 001b081cc1bfd24657e2dccbd9c8289f9a9d67a5. This change was done as the above commit introduces a regression in type inference. Regression test located at `tests/ui/type-inference/issue-113283-alllocator-trait-eq.rs`
2023-07-02Rollup merge of #113253 - nurmukhametdaniyar:rc_from_cstr_doc_fix, r=NilstriebMatthias Krüger-1/+1
Fixed documentation of from<CString> for Rc<CStr>: Arc -> Rc Fix #113131
2023-07-02fixed documentation of from<CString> for Rc<CStr>: Arc -> RcDaniyar Nurmukhamet-1/+1
2023-07-01Remove lifetime bound for A for `impl Extend<&'a T> for Vec<T, A>`.Zachary S-3/+3
2023-06-30Add support for allocators in `Rc` and `Arc`Cyborus04-1/+1
2023-06-30Add support for allocators in `Rc` and `Arc`Cyborus04-300/+1518
2023-06-29Fix document examples of Vec::from_raw_parts and Vec::from_raw_parts_inLi Zhanhui-14/+15
Signed-off-by: Li Zhanhui <lizhanhui@gmail.com>
2023-06-27Rollup merge of #112628 - gootorov:box_alloc_partialeq, r=joshtriplettMatthias Krüger-9/+26
Allow comparing `Box`es with different allocators Currently, comparing `Box`es over different allocators is not allowed: ```Rust error[E0308]: mismatched types --> library/alloc/tests/boxed.rs:22:20 | 22 | assert_eq!(b1, b2); | ^^ expected `Box<{integer}, ConstAllocator>`, found `Box<{integer}, AnotherAllocator>` | = note: expected struct `Box<{integer}, ConstAllocator>` found struct `Box<{integer}, AnotherAllocator>` For more information about this error, try `rustc --explain E0308`. error: could not compile `alloc` (test "collectionstests") due to previous error ``` This PR lifts this limitation
2023-06-26Rollup merge of #112677 - the8472:remove-unusued-field, r=JohnTitorTakayuki Maeda-9/+1
remove unused field Followup to #104455. The field is no longer needed since ExtractIf (previously DrainFilter) doesn't keep draining in its drop impl.
2023-06-21Auto merge of #112877 - Nilstrieb:rollup-5g5hegl, r=Nilstriebbors-2/+7
Rollup of 6 pull requests Successful merges: - #112632 (Implement PartialOrd for `Vec`s over different allocators) - #112759 (Make closure_saved_names_of_captured_variables a query. ) - #112772 (Add a fully fledged `Clause` type, rename old `Clause` to `ClauseKind`) - #112790 (Syntactically accept `become` expressions (explicit tail calls experiment)) - #112830 (More codegen cleanups) - #112844 (Add retag in MIR transform: `Adt` for `Unique` may contain a reference) r? `@ghost` `@rustbot` modify labels: rollup
2023-06-21Rollup merge of #112632 - gootorov:vec_alloc_partialeq, r=dtolnayNilstrieb-2/+7
Implement PartialOrd for `Vec`s over different allocators It is already possible to `PartialEq` `Vec`s with different allocators, but that is not the case with `PartialOrd`.
2023-06-21Auto merge of #106450 - albertlarsan68:fix-arc-ptr-eq, r=Amanieubors-10/+10
Make `{Arc,Rc,Weak}::ptr_eq` ignore pointer metadata FCP completed in https://github.com/rust-lang/rust/issues/103763#issuecomment-1362267967 Closes #103763
2023-06-19Introduce `alloc::::UniqueRc`Eric Holk-3/+184
This is an `Rc` that is guaranteed to only have one strong reference. Because it is uniquely owned, it can safely implement `DerefMut`, which allows programs to have an initialization phase where structures inside the `Rc` can be mutated. The `UniqueRc` can then be converted to a regular `Rc`, allowing sharing and but read-only access. During the "initialization phase," weak references can be created, but attempting to upgrade these will fail until the `UniqueRc` has been converted to a regular `Rc`. This feature can be useful to create cyclic data structures. This API is an implementation based on the feedback provided to the ACP at https://github.com/rust-lang/libs-team/issues/90.
2023-06-18alloc: Allow comparing `Box`s over different allocatorsIgor Gutorov-9/+26
2023-06-18alloc: Implement PartialOrd for `Vec`s over different allocatorsIgor Gutorov-2/+7
2023-06-17Auto merge of #100036 - DrMeepster:box_free_free_box, r=oli-obkbors-21/+28
Remove `box_free` lang item This PR removes the `box_free` lang item, replacing it with `Box`'s `Drop` impl. Box dropping is still slightly magic because the contained value is still dropped by the compiler.
2023-06-16remove box_free and replace with drop implDrMeepster-21/+28
2023-06-16Rollup merge of #112535 - RalfJung:miri-test-libstd, r=cuviperDylan DPC-5/+5
reorder attributes to make miri-test-libstd work again Fixes fallout from https://github.com/rust-lang/rust/pull/110141
2023-06-15remove unused fieldThe 8472-9/+1
since DrainFilter no longer continues draining when it's dropped the panic tracking is no longer needed.
2023-06-15Auto merge of #104455 - the8472:dont-drain-on-drop, r=Amanieubors-392/+283
Don't drain-on-drop in DrainFilter impls of various collections. This removes drain-on-drop behavior from various unstable DrainFilter impls (not yet for HashSet/Map) because that behavior [is problematic](https://github.com/rust-lang/rust/issues/43244#issuecomment-641638196) (because it can lead to panic-in-drop when user closures panic) and may become forbidden if [this draft RFC passes](https://github.com/rust-lang/rfcs/pull/3288). closes #101122 [ACP](https://github.com/rust-lang/libs-team/issues/136) affected tracking issues * #43244 * #70530 * #59618 Related hashbrown update: https://github.com/rust-lang/hashbrown/pull/374
2023-06-14Rollup merge of #109814 - est31:stabilize_string_leak, r=AmanieuMatthias Krüger-7/+8
Stabilize String::leak Stabilizes the following API: ```Rust impl String { pub fn leak(self) -> &'static mut str; } ``` closes #102929 blocked by having an FCP for stabilization.
2023-06-14s/drain_filter/extract_if/ for Vec, Btree{Map,Set} and LinkedListThe 8472-151/+146
2023-06-14remove drain-on-drop behavior from linked_list::DrainFilter and add #[must_use]The 8472-30/+14
2023-06-14remove drain-on-drop behavior from BTree{Set,Map}::DrainFilter and add ↵The 8472-58/+40
#[must_use]
2023-06-14remove drain-on-drop behavior from vec::DrainFilter and add #[must_use]The 8472-91/+21
2023-06-13Auto merge of #112314 - ferrocene:pa-core-alloc-abort, r=bjorn3bors-0/+18
Ignore `core`, `alloc` and `test` tests that require unwinding on `-C panic=abort` Some of the tests for `core` and `alloc` require unwinding through their use of `catch_unwind`. These tests fail when testing using `-C panic=abort` (in my case through a target without unwinding support, and `-Z panic-abort-tests`), while they should be ignored as they don't indicate a failure. This PR marks all of these tests with this attribute: ```rust #[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")] ``` I'm not aware of a way to test this on rust-lang/rust's CI, as we don't test any target with `-C panic=abort`, but I tested this locally on a Ferrocene target and it does indeed make the test suite pass.
2023-06-13ignore core, alloc and test tests that require unwinding on panic=abortPietro Albini-0/+18
2023-06-11Impl allocator function for iteratorsyanchith-0/+32
2023-06-11Remove explicit lifetimesyanchith-20/+20
2023-06-11reorder attributes to make miri-test-libstd work againRalf Jung-5/+5
2023-06-09Don't explicitly name Globalyanchith-1/+1
2023-06-09Pass tidy againyanchith-5/+1
2023-06-09Add allocator functionyanchith-0/+7
2023-06-09Reallocatorize after mergeyanchith-12/+16
2023-06-09Merge branch 'master' into binary-heap-tayanchith-2776/+5512
2023-06-04Remove redundant example of `BTreeSet::iter`zica-13/+0
2023-06-04Remove ExtendWith and ExtendElementGrisha Vartanyan-26/+10
2023-05-31Clarify behavior of inclusive bounds in BTreeMap::{lower,upper}_boundchloekek-0/+8
2023-05-30Bump to latest beta compilerMark Rousskov-2/+0
2023-05-30Swap out CURRENT_RUSTC_VERSION to 1.71.0Mark Rousskov-1/+1
2023-05-28Stabilize String::leakest31-7/+8
2023-05-27Rollup merge of #111656 - finnbear:string_leak_unbounded_lifetime, r=AmanieuMatthias Krüger-2/+2
Use an unbounded lifetime in `String::leak`. Using `'a` instead of `'static` is predicted to make the process of making `String` generic over an allocator easier/less of a breaking change. See: - https://github.com/rust-lang/rust/pull/109814#issuecomment-1550164195 - https://github.com/rust-lang/rust/pull/109814#issuecomment-1550250163 ACP: https://github.com/rust-lang/libs-team/issues/109