about summary refs log tree commit diff
path: root/library/alloc/src/raw_vec
AgeCommit message (Collapse)AuthorLines
2025-09-25Remove most `#[track_caller]` from allocating Vec methodsNoratrieb-17/+0
They cause significant binary size overhead while contributing little value. Also removes them from the wrapping String methods that do not panic.
2025-09-25Rollup merge of #145067 - btj:patch-3, r=tgross35Stuart Cook-36/+123
RawVecInner: add missing `unsafe` to unsafe fns Some (module-private) functions in `library/alloc/src/raw_vec/mod.rs` are unsafe (i.e. may cause UB when called from safe code) but are not marked `unsafe`. Specifically: - `RawVecInner::grow_exact` causes UB if called with `len` and `additional` arguments such that `len + additional` is less than the current capacity. Indeed, in that case it calls [Allocator::grow](https://doc.rust-lang.org/std/alloc/trait.Allocator.html#method.grow) with a `new_layout` that is smaller than `old_layout`, which violates a safety precondition. - The RawVecInner methods for resizing the buffer cause UB if called with an `elem_layout` different from the one used to initially allocate the buffer, because in that case `Allocator::grow` or `Allocator::shrink` are called with an `old_layout` that does not *fit* the allocated block, which violates a safety precondition. - `RawVecInner::current_memory` might cause UB if called with an `elem_layout` different from the one used to initially allocate the buffer, because the `unchecked_mul` might overflow. - Furthermore, these methods cause UB if called with an `elem_layout` where the size is not a multiple of the alignment. This is because `Layout::repeat` is used (in `layout_array`) to compute the allocation's layout when allocating, which includes padding to ensure alignment of array elements, but simple multiplication is used (in `current_memory`) to compute the old allocation's layout when resizing or deallocating, which would cause the layout used to resize or deallocate to not *fit* the allocated block, which violates a safety precondition. I discovered these issues while performing formal verification of `library/alloc/src/raw_vec/mod.rs` per [Challenge 19](https://model-checking.github.io/verify-rust-std/challenges/0019-rawvec.html) of the [AWS Rust Standard Library Verification Contest](https://aws.amazon.com/blogs/opensource/verify-the-safety-of-the-rust-standard-library/).
2025-09-21Change the cfg to a dashBen Kimock-1/+1
2025-09-21Add panic=immediate-abortBen Kimock-1/+1
2025-09-05RawVecInner: add missing `unsafe` to unsafe fnsBart Jacobs-36/+123
- RawVecInner::grow_exact causes UB if called with len and additional arguments such that len + additional is less than the current capacity. Indeed, in that case it calls Allocator::grow with a new_layout that is smaller than old_layout, which violates a safety precondition. - All RawVecInner methods for resizing the buffer cause UB if called with an elem_layout different from the one used to initially allocate the buffer, because in that case Allocator::grow/shrink is called with an old_layout that does not fit the allocated block, which violates a safety precondition. - RawVecInner::current_memory might cause UB if called with an elem_layout different from the one used to initially allocate the buffer, because the unchecked_mul might overflow. - Furthermore, these methods cause UB if called with an elem_layout where the size is not a multiple of the alignment. This is because Layout::repeat is used (in layout_array) to compute the allocation's layout when allocating, which includes padding to ensure alignment of array elements, but simple multiplication is used (in current_memory) to compute the old allocation's layout when resizing or deallocating, which would cause the layout used to resize or deallocate to not fit the allocated block, which violates a safety precondition.
2025-09-04Rollup merge of #145750 - btj:drop-alloc-guard, r=tgross35Stuart Cook-25/+2
raw_vec.rs: Remove superfluous fn alloc_guard `alloc_guard` checks that its argument is at most `isize::MAX`, but it is called only with layout sizes, which are already guaranteed to be at most `isize::MAX`.
2025-09-03raw_vec.rs: Remove superfluous fn alloc_guardBart Jacobs-25/+2
It checks that its argument is at most isize::MAX, but it is called only with layout sizes, which are already guaranteed to be at most isize::MAX.
2025-08-26Fix typo in commentTobias Stoeckmann-1/+1
Turn "any heap allocators" into "any heap allocator".
2025-07-22Rename `tests/codegen` into `tests/codegen-llvm`Guillaume Gomez-1/+1
2025-05-05Simplify `Vec::as_non_null` implementation and make it `const`Vilim Lendvaj-1/+1
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/+5
Encodes the safety constraint that `Unique`'s pointer must be non-zero into the API.
2025-03-07Add commentsbjorn3-0/+3
2025-03-07Fully test the alloc crate through alloctestsbjorn3-0/+1
For the tests that make use of internal implementation details, we include the module to test using #[path] in alloctests now.
2025-03-07Move all alloc integration tests to a new alloctests cratebjorn3-0/+818
2025-03-06library: Use size_of from the prelude instead of importedThalia Archibald-2/+1
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.
2024-08-09Polymorphize RawVecBen Kimock-19/+8
2024-07-29Reformat `use` declarations.Nicholas Nethercote-1/+2
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-03-01try_with_capacity for RawVecKornel-3/+4
2023-12-11add more niches to rawvecThe 8472-0/+9
2021-11-26Add a unit test for zero-sized types in `RawVec`.Nicholas Nethercote-0/+84
Because there's some subtle behaviour specific to zero-sized types and it's currently not well tested.
2020-12-04 Rename `AllocRef` to `Allocator` and `(de)alloc` to `(de)allocate`Tim Diekmann-5/+5
2020-09-28Rename AllocErr to AllocErrorJacob Hughes-3/+3
2020-09-22removing &mut self for other methods of AllocRefblitzerr-1/+1
2020-09-21replaced cell::update with cell::[g|s]etblitzerr-5/+1
2020-09-21Added feature flag to use cell_updateblitzerr-0/+4
2020-09-21Changing the alloc() to accept &self instead of &mut selfblitzerr-7/+8
2020-08-04Replace `Memoryblock` with `NonNull<[u8]>`Tim Diekmann-1/+1
2020-07-28Remove in-place allocation and revert to separate methods for zeroed allocationsTim Diekmann-2/+2
Fix docs
2020-07-27mv std libs to library/mark-0/+78