about summary refs log tree commit diff
path: root/library/alloc
AgeCommit message (Collapse)AuthorLines
2025-04-27use generic Atomic type where possibleChristopher Durham-5/+6
in core/alloc/std only for now, and ignoring test files Co-authored-by: Pavel Grigorenko <GrigorenkoPV@ya.ru>
2025-04-24Rollup merge of #140232 - nnethercote:rm-unnecessary-clones, r=SparrowLiiMatthias Krüger-1/+1
Remove unnecessary clones r? `@SparrowLii`
2025-04-24Remove some unnecessary clones.Nicholas Nethercote-1/+1
I found these by grepping for `&[a-z_\.]*\.clone()`, i.e. expressions like `&a.b.clone()`, which are sometimes unnecessary clones, and also looking at clones nearby to cases like that.
2025-04-22Update `compiler_builtins` to 0.1.156Trevor Gross-1/+1
Includes the following changes: * Provide `abort` on AVR [1] [1]: https://github.com/rust-lang/compiler-builtins/pull/830
2025-04-21Rollup merge of #140118 - tamird:cstr-cleanup, r=joboetChris Denton-3/+3
{B,C}Str: minor cleanup (hopefully) uncontroversial bits extracted from #139994.
2025-04-20Implement lint against dangerous implicit autorefsUrgau-1/+1
2025-04-20Add `#[rustc_no_implicit_autorefs]` and apply it to std methodsUrgau-0/+2
2025-04-19Rollup merge of #139922 - jnqnfe:cstr_doc_fix, r=jhprattChris Denton-1/+1
fix incorrect type in cstr `to_string_lossy()` docs Restoring what it said prior to commit 67065fe in which it was changed incorrectly with no supporting explanation. Closes #139835.
2025-04-18Invert `<CString as Deref>::deref` and `CString::as_c_str`Tamir Duberstein-3/+3
This is consistent with the style of `ByteString`.
2025-04-17Update `compiler-builtins` to 0.1.155Trevor Gross-1/+1
Includes the following changes: * Replace `#[naked]` with `#[unsafe(naked)]` [1] [2] * Replace `bl!` with `asm_sym` [3] [1]: https://github.com/rust-lang/compiler-builtins/pull/817 [2]: https://github.com/rust-lang/compiler-builtins/pull/821 [3]: https://github.com/rust-lang/compiler-builtins/pull/820
2025-04-16fix incorrect type in cstr `to_string_lossy()` docsLyndon Brown-1/+1
Restoring what it said prior to commit 67065fe in which it was changed incorrectly with no supporting explanation. Closes #139835.
2025-04-12Optimize `ToString` implementation for integersGuillaume Gomez-0/+48
2025-04-12Fix typo in documentationGenYuLi-1/+1
Correct the misspelling of "indentifier" to "identifier" in `library/alloc/src/fmt.rs`.
2025-04-11Rollup merge of #139600 - tgross35:update-builtins, r=tgross35Stuart Cook-1/+1
Update `compiler-builtins` to 0.1.153 Includes the following changes: * Avoid OOB access in `memcpy` and `memmove` [1] * Enable intrinsics on AVR [2] * `libm` updates to avoid using `core::arch` vector intrinsics [3] * Re-enable `f16` on aarch64 without Neon [4] [1]: https://github.com/rust-lang/compiler-builtins/pull/799 [2]: https://github.com/rust-lang/compiler-builtins/pull/791 [3]: https://github.com/rust-lang/compiler-builtins/pull/814 [4]: https://github.com/rust-lang/compiler-builtins/pull/809
2025-04-10Update `compiler-builtins` to 0.1.153Trevor Gross-1/+1
Includes the following changes: * Avoid OOB access in `memcpy` and `memmove` [1] * Enable intrinsics on AVR [2] * `libm` updates to avoid using `core::arch` vector intrinsics [3] * Re-enable `f16` on aarch64 without Neon [4] [1]: https://github.com/rust-lang/compiler-builtins/pull/799 [2]: https://github.com/rust-lang/compiler-builtins/pull/791 [3]: https://github.com/rust-lang/compiler-builtins/pull/814 [4]: https://github.com/rust-lang/compiler-builtins/pull/809
2025-04-10Auto merge of #139279 - BoxyUwU:bump-boostrap, r=jieyouxubors-35/+35
Bump boostrap compiler to new beta try-job: `*msvc*`
2025-04-09intra-doc linkBoxy-1/+1
2025-04-09update cfgsBoxy-7/+7
2025-04-09replace version placeholderBoxy-27/+27
2025-04-09Speed up `String::push` and `String::insert`lincot-18/+48
Improve performance of `String` methods by avoiding unnecessary memcpy for the character bytes, with added codegen check to ensure compliance.
2025-04-08document panic behavior of Vec::resize and Vec::resize_withJonathan Gruner-0/+8
2025-04-06Auto merge of #138951 - jwnrt:alloc-raw-vec-strict-prov, r=Noratriebbors-5/+6
Replace last `usize` -> `ptr` transmute in `alloc` with strict provenance API This replaces the `usize -> ptr` transmute in `RawVecInner::new_in` with a strict provenance API (`NonNull::without_provenance`). The API is changed to take an `Alignment` which encodes the non-null constraint needed for `Unique` and allows us to do the construction safely. Two internal-only APIs were added to let us avoid UB-checking in this hot code: `Layout::alignment` to get the `Alignment` type directly rather than as a `usize`, and `Unique::from_non_null` to create `Unique` in const context without a transmute.
2025-04-03Fix testing with randomized layouts enabledbjorn3-1/+0
2025-03-30Rollup merge of #139141 - mejrs:on_unimpl, r=NoratriebJacob Pratt-8/+0
Switch some rustc_on_unimplemented uses to diagnostic::on_unimplemented The use on the SliceIndex impl appears unreachable, there is no mention of "vector indices" in any test output and I could not get it to show up in error messages.
2025-03-30Delete unreacheable `#[rustc_on_unimplemented]`mejrs-8/+0
2025-03-29Auto merge of #133572 - frank-king:feature/unique_arc, r=Amanieubors-1/+411
Implement `alloc::sync::UniqueArc` This implements the `alloc::sync::UniqueArc` part of #112566.
2025-03-26Swap usize -> ptr transmute for strict_pov APIJames Wainwright-2/+1
Removes some unsafety and reduces the number of `usize` -> `ptr` transmutes which might be helpful for CHERI-like targets in the future.
2025-03-26Pass `Alignment` for `RawVecInner::new_in`James Wainwright-4/+6
Encodes the safety constraint that `Unique`'s pointer must be non-zero into the API.
2025-03-24Rollup merge of #138800 - RalfJung:const_box, r=oli-obkMatthias Krüger-8/+4
remove remnants of const_box feature This feature requires major design work, and the few methods it gates currently aren't actually useful. Let's reset to a clean slate so when a design materializes, we can start from scratch. Closes https://github.com/rust-lang/rust/issues/92521 by removing the feature it tracks. r? ````@oli-obk````
2025-03-24Update `compiler-builtins` to 0.1.152Trevor Gross-1/+1
Includes the following changes related to unordered atomics: * Remove element_unordered_atomic intrinsics [1] * Remove use of `atomic_load_unordered` and undefined behaviour [2] There are a handful of other small changes, but nothing else user-visible. [1]: https://github.com/rust-lang/compiler-builtins/pull/789 [2]: https://github.com/rust-lang/compiler-builtins/pull/790
2025-03-22Remove `PartialEq::ne` for `UniqueArc`Frank King-19/+0
2025-03-22Add more APIs for UniqueArcFrank King-5/+250
2025-03-22Make UniqueArc invariant for soundnessFrank King-2/+6
2025-03-22Implement `UniqueArc`Frank King-1/+181
2025-03-21remove remnants of const_box featureRalf Jung-8/+4
2025-03-17Mark imports of #[rustc_std_internal_symbol] items with this attributebjorn3-3/+8
This ensures that they will be correctly mangled in a future commit.
2025-03-17Rollup merge of #138341 - xizheyin:issue-138322, r=joboetJacob Pratt-3/+23
std: Mention clone-on-write mutation in Arc<T> Fixes #138322 r? libs
2025-03-16Rollup merge of #136293 - hkBst:patch-32, r=AmanieuJacob Pratt-0/+13
document capacity for ZST as example The main text already covers this, although it provides weaker guarantees, but I think an example in the right spot does not hurt. Fixes #80747
2025-03-16Rollup merge of #138303 - DiuDiu777:rc-fix, r=Mark-Simulacrum许杰友 Jieyou Xu (Joe)-20/+44
Fix Ptr inconsistency in {Rc,Arc} ### PR Description This pr aims to address the problem discussed on [zulip](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Inconsistency.20in.20.7BRc.2CArc.7D's.20ptr.20requirements/with/504259637). ### Problem Clarification As this post presents, the `{Rc, Arc}::{in/de-crement_strong_count_/in}` do not limit the layout of the memory that `ptr` points to, while internally `Rc::from_raw_in` is called directly. UB doesn't just appear when the strong count is decremented to zero. Miri also detects the UB of `out-of-bounds pointer use` when increment strong count is called on a pointer with an incorrect layout(shown as below). ```rust use std::rc::Rc; #[repr(align(8))] struct Aligned8(u64); #[repr(align(16))] struct Aligned16(u64); fn main() { let rc: Rc<Aligned8> = Rc::new(Aligned8(42)); let raw_ptr = Rc::into_raw(rc); unsafe { Rc::increment_strong_count(raw_ptr as *const Aligned16); } } ``` Miri output: ``` error: Undefined Behavior: out-of-bounds pointer use: expected a pointer to 32 bytes of memory, but got alloc954 which is only 24 bytes from the end of the allocation ```
2025-03-13Rollup merge of #138162 - ehuss:library-2024, r=cuviperMatthias Krüger-1/+1
Update the standard library to Rust 2024 This updates the standard library to Rust 2024. This includes the following notable changes: - Macros are updated to use new expression fragment specifiers. This PR includes a test to illustrate the changes, primarily allowing `const {...}` expressions now. - Some tests show a change in MIR drop order. We do not believe this will be an observable change ([see zulip discussion](https://rust-lang.zulipchat.com/#narrow/channel/268952-edition/topic/standard.20library.20migration/near/500972873)). Fixes https://github.com/rust-lang/rust/issues/133081
2025-03-12Rollup merge of #138387 - RalfJung:intrinsic-arg-names, r=oli-obkMatthias Krüger-1/+1
intrinsics: remove unnecessary leading underscore from argument names This is unnecessary since https://github.com/rust-lang/rust/pull/135840.
2025-03-12Rollup merge of #138161 - HeroicKatora:heap-peek-mut-refresh, r=dtolnayMatthias Krüger-4/+78
Add PeekMut::refresh I'm not sure if this should go through ACP or not. BinaryHeap is not the most critical data structure in the standard library and it would be understandable if maintainer throughput is thus too limited to accept this PR without a proper design phase that ensures the required understanding of consequence over a longer time period. This aims to improve the useability of heaps for priority-based work queues. In certain scenarios, modifications on the most relevant or critical items are performed until a condition that determines the work items have been sufficiently addressed. For instance the criticality could be a deadline that is relaxed whenever some part of a work item is completed. Such a loop will repeatedly access the most critical item and put it back in a sorted position when it is complete. Crucially, due to the ordering invariant we know that all necessary work was performed when the completed item remains the most critical. Getting this information from the heap position avoids a (potentially more costly) check on the item state itself. A customized `drop` with boolean result would avoid up to two more comparisons performed in both the last no-op refresh and Drop code but this occurs once in each execution of the above scenario whereas refresh occurs any number of times. Also note that the comparison overhead of Drop is only taken if the element is mutably inspected to determine the end condition, i.e. not when refresh itself is the break condition.
2025-03-12intrinsics: remove unnecessary leading underscore from argument namesRalf Jung-1/+1
2025-03-11Migrate alloc to Rust 2024Eric Huss-1/+1
2025-03-11Add PeekMut::refreshAurelia Molzer-4/+78
This improves the useability of heaps for priority-based work queues. In certain scenarios, modifications on the most relevant or critical items are performed until a condition that determines the work items have been sufficiently addressed. The loop will repeatedly access the most critical item and put it back in a sorted position when it is complete. Crucially, due to the ordering invariant we know that all work was performed when the completed item remains the most critical. Getting this information from the heap position avoids a (potentially more costly) check on the item state itself. A customized `drop` with boolean result would avoid up to two more comparisons performed in both the last no-op refresh and Drop code but this occurs once in each execution of the above scenario whereas refresh occurs any number of times. Also note that the comparison overhead of Drop is only taken if the element is mutably inspected to determine the end condition, i.e. not when refresh itself is the break condition.
2025-03-11std: Mention clone-on-write mutation in Arc<T>xizheyin-3/+23
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-03-10fix copy typoLemonJ-4/+4
2025-03-10fix ptr inconsistency in Rc ArcLemonJ-23/+47
2025-03-09document capacity for ZST as example and proseMarijn Schouten-0/+13
2025-03-08Stabilize `const_vec_string_slice`Martin Habovstiak-15/+16
This feature was approved for stabilization in https://github.com/rust-lang/rust/issues/129041#issuecomment-2508940661 so this change stabilizes it.