about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2024-05-12Auto merge of #125012 - RalfJung:format-error, r=Mark-Simulacrum,workingjubileebors-1/+3
io::Write::write_fmt: panic if the formatter fails when the stream does not fail Follow-up to https://github.com/rust-lang/rust/pull/124954
2024-05-11Rollup merge of #124981 - zachs18:rc-allocator-generalize-1, r=Mark-SimulacrumMatthias Krüger-32/+33
Relax allocator requirements on some Rc/Arc APIs. Split out from #119761 * Remove `A: Clone` bound from `Rc::assume_init`(s), `Rc::downcast`, and `Rc::downcast_unchecked` (`Arc` methods were already relaxed by #120445) * Make `From<Rc<[T; N]>> for Rc<[T]>` allocator-aware (`Arc`'s already is). * Remove `A: Clone` from `Rc/Arc::unwrap_or_clone` Internal changes: * Made `Arc::internal_into_inner_with_allocator` method into `Arc::into_inner_with_allocator` associated fn. * Add private `Rc::into_inner_with_allocator` (to match Arc), so other fns don't have to juggle `ManuallyDrop`.
2024-05-11io::Write::write_fmt: panic if the formatter fails when the stream does not failRalf Jung-1/+3
2024-05-10Relax A: Clone requirement on Rc/Arc::unwrap_or_clone.Zachary S-0/+4
2024-05-10Relax allocator requirements on some Rc APIs.Zachary S-32/+29
* Remove A: Clone bound from Rc::assume_init, Rc::downcast, and Rc::downcast_unchecked. * Make From<Rc<[T; N]>> for Rc<[T]> allocator-aware. Internal changes: * Made Arc::internal_into_inner_with_allocator method into Arc::into_inner_with_allocator associated fn. * Add private Rc::into_inner_with_allocator (to match Arc), so other fns don't have to juggle ManuallyDrop.
2024-05-10Add fn allocator method to rc/sync::Weak. Relax Rc<T>/Arc<T>::allocator to ↵Zachary S-20/+36
allow unsized T.
2024-05-09Document proper usage of `fmt::Error` and `fmt()`'s `Result`.Kevin Reid-1/+1
Documentation of these properties previously existed in a lone paragraph in the `fmt` module's documentation: <https://doc.rust-lang.org/1.78.0/std/fmt/index.html#formatting-traits> However, users looking to implement a formatting trait won't necessarily look there. Therefore, let's add the critical information (that formatting per se is infallible) to all the involved items.
2024-05-08fix #124714 str.to_lowercase sigma handlingMarcondiro-4/+6
2024-05-07Move `test_shrink_to_unwind` to its own file.Markus Everling-55/+1
This way, no other test can be tripped up by `test_shrink_to_unwind` changing the alloc error hook.
2024-05-07Fix `VecDeque::shrink_to` UB when `handle_alloc_error` unwinds.Markus Everling-2/+120
Luckily it's comparatively simple to just restore the `VecDeque` into a valid state on unwinds.
2024-05-05alloc: implement FromIterator for Box<str>Caleb Sander-4/+54
Box<[T]> implements FromIterator<T> using Vec<T> + into_boxed_slice(). Add analogous FromIterator implementations for Box<str> matching the current implementations for String. Remove the Global allocator requirement for FromIterator<Box<str>> too.
2024-05-05Rollup merge of #124749 - RossSmyth:stable_range, r=davidtwcoGuillaume Gomez-1/+1
Stabilize exclusive_range_pattern (v2) This PR is identical to #124459, which was approved and merged but then removed from master by a force-push due to a [CI bug](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/ci.20broken.3F). r? ghost Original PR description: --- Stabilization report: https://github.com/rust-lang/rust/issues/37854#issuecomment-1842398130 FCP: https://github.com/rust-lang/rust/issues/37854#issuecomment-1872520294 Stabilization was blocked by a lint that was merged here: #118879 Documentation PR is here: rust-lang/reference#1484 `@rustbot` label +F-exclusive_range_pattern +T-lang
2024-05-03Rollup merge of #124593 - GKFX:cstr-literals-in-api-docs, r=workingjubileeMatthias Krüger-9/+5
Describe and use CStr literals in CStr and CString docs Mention CStr literals in the description of both types, and use them in some of the code samples for CStr. This is intended to make C string literals more discoverable. Additionally, I don't think the orange "This example is not tested" warnings are very encouraging, so I have made the examples on `CStr` build.
2024-05-03Rollup merge of #124441 - bravequickcleverfibreyarn:string.rs, r=AmanieuMatthias Krüger-1/+1
String.truncate comment microfix (greater or equal) String.truncate calls Vec.truncate, in turn, and that states "is greater or equal to". Beside common sense.
2024-05-03Rollup merge of #123480 - Nadrieril:impl-all-derefpures, r=compiler-errorsMatthias Krüger-1/+4
deref patterns: impl `DerefPure` for more std types Context: [deref patterns](https://github.com/rust-lang/rust/issues/87121). The requirements of `DerefPure` aren't precise yet, but these types unambiguously satisfy them. Interestingly, a hypothetical `impl DerefMut for Cow` that does a `Clone` would *not* be eligible for `DerefPure` if we allow mixing deref patterns with normal patterns. If the following is exhaustive then the `DerefMut` would cause UB: ```rust match &mut Cow::Borrowed(&()) { Cow::Owned(_) => ..., // Doesn't match deref!(_x) if false => ..., // Causes the variant to switch to `Owned` Cow::Borrowed(_) => ..., // Doesn't match // We reach unreachable } ```
2024-05-02Stabilize exclusive_rangeRoss Smyth-1/+1
2024-05-01Step bootstrap cfgsMark Rousskov-3/+1
2024-05-01Replace version placeholders for 1.79Mark Rousskov-1/+1
2024-05-01Describe and use CStr literals in CStr and CString docsGeorge Bateman-9/+5
2024-04-28Stabilize `non_null_convenience`Trevor Gross-1/+0
Fully stabilize the following API, including const where applicable: impl <T> NonNull<T> { pub const unsafe fn offset(self, count: isize) -> Self; pub const unsafe fn add(self, count: usize) -> Self; pub const unsafe fn sub(self, count: usize) -> Self; pub const unsafe fn offset_from(self, origin: NonNull<T>) -> isize; pub const unsafe fn read(self) -> T; pub unsafe fn read_volatile(self) -> T; pub const unsafe fn read_unaligned(self) -> T; pub unsafe fn write_volatile(self, val: T); pub unsafe fn replace(self, src: T) -> T; } impl<T: ?Sized> NonNull<T> { pub const unsafe fn byte_offset(self, count: isize) -> Self; pub const unsafe fn byte_add(self, count: usize) -> Self; pub const unsafe fn byte_sub(self, count: usize) -> Self; pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: NonNull<U>) -> isize; pub unsafe fn drop_in_place(self); } Stabilize the following without const: impl <T> NonNull<T> { // const under `const_intrinsic_copy` pub const unsafe fn copy_to(self, dest: NonNull<T>, count: usize); pub const unsafe fn copy_to_nonoverlapping(self, dest: NonNull<T>, count: usize); pub const unsafe fn copy_from(self, src: NonNull<T>, count: usize); pub const unsafe fn copy_from_nonoverlapping(self, src: NonNull<T>, count: usize); // const under `const_ptr_write` pub const unsafe fn write(self, val: T); pub const unsafe fn write_bytes(self, val: u8, count: usize); pub const unsafe fn write_unaligned(self, val: T); // const under `const_swap` pub const unsafe fn swap(self, with: NonNull<T>); // const under `const_align_offset` pub const fn align_offset(self, align: usize) -> usize; // const under `const_pointer_is_aligned` pub const fn is_aligned(self) -> bool; } Left the following unstable: impl <T> NonNull<T> { // moved gate to `ptr_sub_ptr` pub const unsafe fn sub_ptr(self, subtracted: NonNull<T>) -> usize; } impl <T: ?Sized> NonNull<T> { // moved gate to `pointer_is_aligned_to` pub const fn is_aligned_to(self, align: usize) -> bool; } Fixes: https://github.com/rust-lang/rust/issues/117691
2024-04-27WS fix.JirCep-1/+1
2024-04-27String.truncate calls Vec.truncate, in turn, and that statesJirCep-1/+1
"is greater or equal to". Beside common sense.
2024-04-27Auto merge of #124432 - zetanumbers:non_copy_into_raw_with_alloc, r=Nilstriebbors-7/+4
Relax `A: Clone` bound for `rc::Weak::into_raw_and_alloc` Makes this method to behave the same way as [`Box::into_raw_with_allocator`](https://doc.rust-lang.org/1.77.2/alloc/boxed/struct.Box.html#method.into_raw_with_allocator) and [`Vec::into_raw_parts_with_alloc`](https://doc.rust-lang.org/1.77.2/alloc/vec/struct.Vec.html#method.into_raw_parts_with_alloc). I have also noticed the inconsistent presence and naming, should probably be addressed in the future.
2024-04-27Relax `A: Clone` bound for `rc::Weak::into_raw_and_alloc`Daria Sukhonina-7/+4
2024-04-26Auto merge of #123909 - dtolnay:utf8chunks, r=joboetbors-5/+2
Stabilize `Utf8Chunks` Pending FCP in https://github.com/rust-lang/rust/issues/99543. This PR includes the proposed modification in https://github.com/rust-lang/libs-team/issues/190 as agreed in https://github.com/rust-lang/rust/issues/99543#issuecomment-2050406568.
2024-04-24Stabilize Utf8ChunksDavid Tolnay-5/+2
2024-04-24fix typo in binary_heap docsThomas Lindae-1/+1
2024-04-24Stabilise `inline_const`Gary Guo-1/+1
2024-04-22Stabilize generic `NonZero`.Markus Reiter-1/+0
2024-04-20Avoid reloading Vec::len across grow_one in pushMark Rousskov-3/+5
This saves an extra load from memory.
2024-04-17Rollup merge of #122201 - coolreader18:doc-clone_from, r=dtolnayMatthias Krüger-18/+78
Document overrides of `clone_from()` in core/std As mentioned in https://github.com/rust-lang/rust/pull/96979#discussion_r1379502413 Specifically, when an override doesn't just forward to an inner type, document the behavior and that it's preferred over simply assigning a clone of source. Also, change instances where the second parameter is "other" to "source". I reused some of the wording over and over for similar impls, but I'm not sure that the wording is actually *good*. Would appreciate feedback about that. Also, now some of these seem to provide pretty specific guarantees about behavior (e.g. will reuse the exact same allocation iff the len is the same), but I was basing it off of the docs for [`Box::clone_from`](https://doc.rust-lang.org/1.75.0/std/boxed/struct.Box.html#method.clone_from-1) - I'm not sure if providing those strong guarantees is actually good or not.
2024-04-17Address commentsNoa-3/+1
2024-04-16Stabilize `BinaryHeap::as_slice`Slanterns-2/+1
2024-04-16Box::into_raw: make Miri understand that this is a box-to-raw castRalf Jung-2/+6
2024-04-15Add vec_deque::Iter::as_slices and friendschloekek-0/+142
Add the following methods, that work similarly to VecDeque::as_slices: - alloc::collections::vec_deque::Iter::as_slices - alloc::collections::vec_deque::IterMut::into_slices - alloc::collections::vec_deque::IterMut::as_slices - alloc::collections::vec_deque::IterMut::as_mut_slices Obtaining slices from a VecDeque iterator was not previously possible.
2024-04-13Rollup merge of #123868 - eduardosm:stabilize-slice_ptr_len, r=jhprattJacob Pratt-1/+0
Stabilize (const_)slice_ptr_len and (const_)slice_ptr_is_empty_nonnull Stabilized API: ```rust impl<T> *mut [T] { pub const fn len(self) -> usize; pub const fn is_empty(self) -> bool; } impl<T> *const [T] { pub const fn len(self) -> usize; pub const fn is_empty(self) -> bool; } impl<T> NonNull<[T]> { pub const fn is_empty(self) -> bool; } ``` FCP completed in tracking issue: https://github.com/rust-lang/rust/issues/71146
2024-04-13Rollup merge of #123835 - saethlin:vec-from-nonnull, r=the8472Jacob Pratt-15/+55
Avoid more NonNull-raw-NonNull roundtrips in Vec r? the8472 The standard library in general has a lot of these round-trips from niched types to their raw innards and back. Such round-trips have overhead in debug builds since https://github.com/rust-lang/rust/pull/120594. I removed some such round-trips in that initial PR and I've been meaning to come back and hunt down more such examples (this is the last item on https://github.com/rust-lang/rust/issues/120848).
2024-04-12Avoid more NonNull-raw-NonNull roundtrips in VecBen Kimock-15/+55
2024-04-12Stabilize (const_)slice_ptr_len and (const_)slice_ptr_is_empty_nonnullEduardo Sánchez Muñoz-1/+0
2024-04-12Auto merge of #120092 - zetanumbers:pin_in_static_allocator, r=Amanieubors-3/+12
Add `A: 'static` bound for `Arc/Rc::pin_in` Analogous to https://github.com/rust-lang/rust/pull/79327 Needed to preserve pin's [drop guarantee](https://doc.rust-lang.org/std/pin/index.html#drop-guarantee)
2024-04-09Rollup merge of #123254 - stepancheg:thin-box-0-const-alloc, r=oli-obkGuillaume Gomez-13/+85
Do not allocate for ZST ThinBox (attempt 2 using const_allocate) There's PR https://github.com/rust-lang/rust/pull/123184 which avoids allocation for ZST ThinBox. That PR has an issue with unsoundness with padding in `MaybeUninit` (see comments in that PR). Also that PR relies on `Freeze` trait. This PR is much simpler implementation which does not have this problem, but it uses `const_allocate` feature. `@oli-obk` suggested that `const_allocate` should not be used for that feature. But I like how easy it to do this feature with `const_allocate`. Maybe it's OK to use `const_allocate` while `ThinBox` is unstable? Or, well, we can abandon this PR. r? `@oli-obk`
2024-04-08Add invariant to VecDeque::pop_* that len < cap if pop successfulPhilippe-Cholet-2/+8
Similar to #114370 for VecDeque instead of Vec. It now uses `core::hint::assert_unchecked`.
2024-04-07make a doctest less slow in MiriRalf Jung-1/+3
2024-04-06remove miri-test-libstd hacks that are no longer neededRalf Jung-6/+0
2024-04-05Do not allocate for ZST ThinBox attempt 2 (using const_allocate)Stepan Koltsov-13/+85
There's PR https://github.com/rust-lang/rust/pull/123184 which avoids allocation for ZST ThinBox. That PR has an issue with unsoundness with misuse of `MaybeUninit` (see comments in that PR). This PR is much simpler implementation which does not have this problem, but it uses `const_allocate` feature.
2024-04-05Auto merge of #123317 - RalfJung:test-in-miri, r=m-ou-se,saethlin,onur-ozkanbors-0/+4
Support running library tests in Miri This adds a new bootstrap subcommand `./x.py miri` which can test libraries in Miri. This is in preparation for eventually doing that as part of bors CI, but this PR only adds the infrastructure, and doesn't enable it yet. `@rust-lang/bootstrap` should this be `x.py test --miri library/core` or `x.py miri library/core`? The flag has the advantage that we don't have to copy all the arguments from `Subcommand::Test`. It has the disadvantage that most test steps just ignore `--miri` and still run tests the regular way. For clippy you went the route of making it a separate subcommand. ~~I went with a flag now as that seemed easier, but I can change this.~~ I made it a new subcommand. Note however that the regular cargo invocation would be `cargo miri test ...`, so `x.py` is still going to be different in that the `test` is omitted. That said, we could also make it `./x.py miri-test` to make that difference smaller -- that's in fact more consistent with the internal name of the command when bootstrap invokes cargo. `@rust-lang/libs` ~~unfortunately this PR does some unholy things to the `lib.rs` files of our library crates.~~ `@m-ou-se` found a way that entirely avoids library-level hacks, except for some new small `lib.miri.rs` files that hopefully you will never have to touch. There's a new hack in cargo-miri but there it is in good company...
2024-04-05Impl `DerefPure` for more std typesNadrieril-1/+4
2024-04-03add 'x.py miri', and make it work for 'library/{core,alloc,std}'Ralf Jung-0/+4
2024-04-02Auto merge of #122945 - andy-k:sorted-vec-example, r=jhprattbors-2/+4
improve example on inserting to a sorted vector to avoid shifting equal elements
2024-04-01doc: mention heap allocation earlier in String docsJani Mustonen-3/+3
Just a tiny addition. Helps with #123263.