about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
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-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-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.
2025-03-08Rollup merge of #136642 - bjorn3:separate_alloctest_crate, r=cuviperJacob Pratt-1198/+138
Put the alloc unit tests in a separate alloctests package Same rationale as https://github.com/rust-lang/rust/pull/135937. This PR has some extra complexity though as a decent amount of tests are testing internal implementation details rather than the public api. As such I opted to include the modules containing the types under test using `#[path]` into the alloctests package. This means that those modules still need `#[cfg(test)]`, but the rest of liballoc no longer need it.
2025-03-07Add commentsbjorn3-0/+6
2025-03-07Fully test the alloc crate through alloctestsbjorn3-531/+132
For the tests that make use of internal implementation details, we include the module to test using #[path] in alloctests now.
2025-03-07Move last remaining Rc test to alloctestsbjorn3-18/+0
2025-03-07Move most Rc tests to alloctestsbjorn3-649/+0
2025-03-07Move all alloc integration tests to a new alloctests cratebjorn3-0/+0
2025-03-07Rollup merge of #134797 - spastorino:ergonomic-ref-counting-1, r=nikomatsakisMatthias Krüger-0/+16
Ergonomic ref counting This is an experimental first version of ergonomic ref counting. This first version implements most of the RFC but doesn't implement any of the optimizations. This was left for following iterations. RFC: https://github.com/rust-lang/rfcs/pull/3680 Tracking issue: https://github.com/rust-lang/rust/issues/132290 Project goal: https://github.com/rust-lang/rust-project-goals/issues/107 r? ```@nikomatsakis```
2025-03-07Rollup merge of #138034 - thaliaarchi:use-prelude-size-of, r=tgross35Matthias Krüger-65/+48
library: Use `size_of` from the prelude instead of imported Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. These functions were added to all preludes in Rust 1.80. try-job: test-various try-job: x86_64-gnu try-job: x86_64-msvc-1
2025-03-06library: Use size_of from the prelude instead of importedThalia Archibald-65/+48
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. These functions were added to all preludes in Rust 1.80.
2025-03-06Add allow(incomplete_features) to allocSantiago Pastorino-0/+1
2025-03-06Add UseCloned trait related codeSantiago Pastorino-0/+15
2025-03-05Rollup merge of #137569 - aDotInTheVoid:for-iurii, r=ibraheemdev许杰友 Jieyou Xu (Joe)-2/+1
Stabilize `string_extend_from_within` FCP'd here: https://github.com/rust-lang/rust/issues/103806#issuecomment-2674989531. Closes #103806.
2025-03-04Rollup merge of #137850 - slanterns:box_uninit_write, r=ibraheemdevJubilee-4/+1
Stabilize `box_uninit_write` Closes: https://github.com/rust-lang/rust/issues/129397.
2025-03-02Rollup merge of #137641 - kpreid:dealloc, r=AmanieuMatthias Krüger-2/+8
More precisely document `Global::deallocate()`'s safety. There is a subtlety which "other conditions must be upheld by the caller" does not capture: `GlobalAlloc`/`alloc::dealloc()` require that the provided layout will be *equal*, not just that it "fits", the layout used to allocate. This is always true here due to how `allocate()`, `grow()`, and `shrink()` are implemented (they never return a larger allocation than requested), but that is a non-local property of the implementation, so it should be documented explicitly. r? libs `@rustbot` label A-allocators
2025-03-01stabilize `box_uninit_write`Slanterns-4/+1
2025-02-25More precisely document `Global::deallocate()`'s safety.Kevin Reid-2/+8
There is a subtlety which "other conditions must be upheld by the caller" does not capture: `GlobalAlloc`/`alloc::dealloc()` require that the provided layout will be *equal*, not just that it "fits", the layout used to allocate. This is always true here due to how `allocate()`, `grow()`, and `shrink()` are implemented (they never return a larger allocation than requested), but that is a non-local property of the implementation, so it should be documented explicitly.
2025-02-25Rollup merge of #137576 - goffrie:setvalzst, r=lcnrLeón Orell Valerian Liehr-1/+1
Don't doc-comment BTreeMap<K, SetValZST, A> This otherwise shows up in documentation as an empty impl block (worse, at the *top* of the docs above the public impls).
2025-02-25Auto merge of #137571 - tgross35:rollup-i1tcnv1, r=tgross35bors-24/+28
Rollup of 8 pull requests Successful merges: - #134655 (Stabilize `hash_extract_if`) - #135933 (Explain how Vec::with_capacity is faithful) - #136668 (Stabilize `core::str::from_utf8_mut` as `const`) - #136775 (Update `String::from_raw_parts` safety requirements) - #137109 (stabilize extract_if) - #137349 (Implement `read_buf` for zkVM stdin) - #137493 (configure.py: don't instruct user to run nonexistent program) - #137516 (remove some unnecessary rustc_const_unstable) r? `@ghost` `@rustbot` modify labels: rollup
2025-02-24Don't doc-comment BTreeMap<K, SetValZST, A>Geoffry Song-1/+1
2025-02-24Rollup merge of #137109 - bend-n:knife, r=oli-obkTrevor Gross-14/+9
stabilize extract_if Tracking issue: #43244 Closes: #43244 FCP completed: https://github.com/rust-lang/rust/issues/43244#issuecomment-2523595704
2025-02-24Rollup merge of #136775 - robertbastian:patch-2, r=AmanieuTrevor Gross-5/+2
Update `String::from_raw_parts` safety requirements These have become out of sync with `Vec::from_raw_part`'s safety requirements, and are likely to diverge again. I think it's safest to just point at `Vec`'s requirements. https://github.com/rust-lang/rust/issues/119206#issuecomment-2180116680
2025-02-24Rollup merge of #135933 - hkBst:patch-19, r=workingjubileeTrevor Gross-5/+17
Explain how Vec::with_capacity is faithful This is a revival of https://github.com/rust-lang/rust/pull/99790 building on the prose of `@workingjubilee` and edits of `@jmaargh.` Closes https://github.com/rust-lang/rust/issues/99385.
2025-02-24Stablize `string_extend_from_within`Alona Enraght-Moony-2/+1
2025-02-24Update string.rsRobert Bastian-2/+2
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2025-02-24remove uses of rustc_intrinsic_must_be_overridden from standard libraryRalf Jung-4/+1
2025-02-23Rollup merge of #137483 - bend-n:😅, r=NoratriebTrevor Gross-5/+5
rename sub_ptr to offset_from_unsigned i also made `byte_sub_ptr` `byte_offset_from_unsigned` fixes #137121 tracking issue #95892
2025-02-23rename sub_ptr 😅bendn-5/+5
2025-02-23stabilize extract_ifbendn-14/+9
2025-02-23Auto merge of #137237 - cuviper:stage0, r=Mark-Simulacrumbors-12/+2
Master bootstrap update https://forge.rust-lang.org/release/process.html#master-bootstrap-update-tuesday r? `@Mark-Simulacrum`
2025-02-23Rollup merge of #137121 - bend-n:master, r=NoratriebMatthias Krüger-1/+0
stabilize `(const_)ptr_sub_ptr` Tracking issue: #95892 Closes #95892 FCP Completed: https://github.com/rust-lang/rust/issues/95892#issuecomment-2561139730 r? ````@Noratrieb````
2025-02-22Somehow these stability attributes were able to be omitted before?ltdk-0/+2
2025-02-22Stabilise c_str_moduleltdk-1/+1
2025-02-21Rollup merge of #136089 - jwong101:box-default-debug-stack-usage, r=AmanieuMatthias Krüger-1/+14
Reduce `Box::default` stack copies in debug mode The `Box::new(T::default())` implementation of `Box::default` only had two stack copies in debug mode, compared to the current version, which has four. By avoiding creating any `MaybeUninit<T>`'s and just writing `T` directly to the `Box` pointer, the stack usage in debug mode remains the same as the old version. Another option would be to mark `Box::write` as `#[inline(always)]`, and change it's implementation to to avoid calling `MaybeUninit::write` (which creates a `MaybeUninit<T>` on the stack) and to use `ptr::write` instead. Fixes: #136043
2025-02-21Explain how Vec::with_capacity is faithfulMarijn Schouten-5/+17
Co-authored-by: Jubilee <workingjubilee@gmail.com> and jmaargh