about summary refs log tree commit diff
path: root/library/alloc
AgeCommit message (Collapse)AuthorLines
2025-01-30Rollup merge of #136215 - btj:patch-1, r=cuviperStuart Cook-2/+2
btree/node.rs: remove incorrect comment from pop_internal_level docs
2025-01-29btree/node.rs: pop_internal_level: does not invalidate other handlesBart Jacobs-0/+3
2025-01-28btree/node.rs: remove incorrect comment from pop_internal_level docsBart Jacobs-3/+0
2025-01-28Auto merge of #136203 - matthiaskrgr:rollup-1k0f44l, r=matthiaskrgrbors-0/+2
Rollup of 9 pull requests Successful merges: - #135869 (Make docs for AtomicUsize::from_mut platform-independent) - #135892 (-Znext-solver: "normalize" signature before checking it mentions self in `deduce_closure_signature`) - #136055 (Implement MIR const trait stability checks) - #136066 (Pass spans to `perform_locally_in_new_solver`) - #136071 ([Clippy] Add vec_reserve & vecdeque_reserve diagnostic items) - #136124 (Arbitrary self types v2: explain test.) - #136149 (Flip the `rustc-rayon`/`indexmap` dependency order) - #136173 (Update comments and sort target_arch in c_char_definition) - #136178 (Update username in build helper example) r? `@ghost` `@rustbot` modify labels: rollup
2025-01-28Rollup merge of #136071 - wowinter13:clippy-add-diagnostic-items, r=flip1995Matthias Krüger-0/+2
[Clippy] Add vec_reserve & vecdeque_reserve diagnostic items I’m currently working on reviving this lint (https://github.com/rust-lang/rust-clippy/pull/10157), and there was [a comment](https://github.com/rust-lang/rust-clippy/pull/10157#discussion_r1091591057) from ``@flip1995`` regarding the necessity of adding new diagnostic items.
2025-01-28Rollup merge of #135805 - DiuDiu777:master, r=NoratriebMatthias Krüger-2/+5
Add missing allocator safety in alloc crate ### PR Description In the previous PR [#135009](https://github.com/rust-lang/rust/pull/135009), PR [#134496](https://github.com/rust-lang/rust/pull/134496), some incomplete API documentation issues have been fixed. Based on these changes, other inconsistencies related to the allocator have also been identified, including: - `Box::from_non_null` - `Box::from_non_null_in` - `Weak::from_raw`
2025-01-28Rollup merge of #135367 - Urgau:unreach_pub-std-3, r=NoratriebMatthias Krüger-210/+251
Enable `unreachable_pub` lint in `alloc` This PR enables the [`unreachable_pub`](https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unreachable-pub) lint as warn in the `alloc` crate. Most of changes are in the btree implementation and in tests. *The diff was mostly generated with `./x.py fix --stage 1 library/alloc/ -- --broken-code`, as well as manual edits for code in macros and in tests.* Continuation of #134286 and #135366 r? libs
2025-01-25Rollup merge of #135948 - bjorn3:update_emscripten_std_tests, r=Mark-SimulacrumJacob Pratt-11/+26
Update emscripten std tests This disables a bunch of emscripten tests that test things emscripten doesn't support and re-enables a whole bunch of tests which now work just fine on emscripten. Tested with `EMCC_CFLAGS="-s MAXIMUM_MEMORY=2GB" ./x.py test library/ --target wasm32-unknown-emscripten`.
2025-01-25[Clippy] Add vec_reserve & vecdeque_reserve diagnostic itemswowinter13-0/+2
2025-01-24Rollup merge of #135728 - hkBst:patch-8, r=joboetMatthias Krüger-3/+5
document order of items in iterator from drain fixes #135710
2025-01-24Rollup merge of #135983 - hkBst:patch-13, r=jhprattMatthias Krüger-4/+3
Doc difference between extend and extend_from_slice fixes #97119
2025-01-24Rollup merge of #135956 - GrigorenkoPV:vec_pop_off, r=dtolnayMatthias Krüger-7/+4
Make `Vec::pop_if` a bit more presentable #135488 minus stabilization. As suggested in https://github.com/rust-lang/rust/pull/135488#issuecomment-2608108210. r? tgross35
2025-01-24Doc difference between extend and extend_from_sliceMarijn Schouten-4/+3
fixes #97119
2025-01-24Remove a bunch of emscripten test ignoresbjorn3-10/+0
They are either outdated as emscripten now supports i128 or they are subsumed by #[cfg_attr(not(panic = "unwind"), ignore]
2025-01-24Fix testing of the standard library with Emscriptenbjorn3-1/+26
This does need EMCC_CFLAGS="-s MAXIMUM_MEMORY=2GB" avoid several OOMs.
2025-01-24Rollup merge of #135890 - GrigorenkoPV:deque-pop-if, r=thomccMatthias Krüger-0/+86
Implement `VecDeque::pop_front_if` & `VecDeque::pop_back_if` Tracking issue: #135889
2025-01-24Make `Vec::pop_if` a bit more presentablePavel Grigorenko-7/+4
2025-01-23Rollup merge of #135073 - joshtriplett:bstr, r=BurntSushiMatthias Krüger-0/+706
Implement `ByteStr` and `ByteString` types Approved ACP: https://github.com/rust-lang/libs-team/issues/502 Tracking issue: https://github.com/rust-lang/rust/issues/134915 These types represent human-readable strings that are conventionally, but not always, UTF-8. The `Debug` impl prints non-UTF-8 bytes using escape sequences, and the `Display` impl uses the Unicode replacement character. This is a minimal implementation of these types and associated trait impls. It does not add any helper methods to other types such as `[u8]` or `Vec<u8>`. I've omitted a few implementations of `AsRef`, `AsMut`, and `Borrow`, when those would be the second implementation for a type (counting the `T` impl), to avoid potential inference failures. We can attempt to add more impls later in standalone commits, and run them through crater. In addition to the `bstr` feature, I've added a `bstr_internals` feature for APIs provided by `core` for use by `alloc` but not currently intended for stabilization. This API and its implementation are based *heavily* on the `bstr` crate by Andrew Gallant (`@BurntSushi).` r? `@BurntSushi`
2025-01-22Implement `VecDeque::pop_front_if` & `VecDeque::pop_back_if`Pavel Grigorenko-0/+86
2025-01-22Remove erroneous `unsafe` in `BTreeSet::upper_bound_mut`Pavel Grigorenko-4/+4
2025-01-22Add doc aliases for BStr and BStringJosh Triplett-0/+1
2025-01-21add missing allocator safety in alloc crateLemonJ-2/+5
2025-01-20alloc: add `#![warn(unreachable_pub)]`Urgau-210/+251
2025-01-19Fix whitespaceMarijn Schouten-1/+1
2025-01-19document order of items in iterator from drainMarijn Schouten-3/+5
fixes 135710
2025-01-16Rollup merge of #134496 - DiuDiu777:fix-doc, r=ibraheemdevMatthias Krüger-2/+6
Update documentation for Arc::from_raw, Arc::increment_strong_count, and Arc::decrement_strong_count to clarify allocator requirement ### Related Issue: This update addresses parts of the issue raised in [#134242](https://github.com/rust-lang/rust/issues/134242), where Arc's documentation lacks `Global Allocator` safety descriptions for three APIs. And this was confirmed by ```@workingjubilee``` : > Wait, nevermind. I apparently forgot the `increment_strong_count` is implicitly A = Global. Ugh. Another reason these things are hard to track, unfortunately. ### PR Description This PR updates the document for the following APIs: - `Arc::from_raw` - `Arc::increment_strong_count` - `Arc::decrement_strong_count` These APIs currently lack an important piece of documentation: **the raw pointer must point to a block of memory allocated by the global allocator**. This crucial detail is specified in the source code but is not reflected in the documentation, which could lead to confusion or incorrect usage by users. ### Problem: The following example demonstrates the potential confusion caused by the lack of documentation: ```rust #![feature(allocator_api)] use std::alloc::{Allocator,AllocError, Layout}; use std::ptr::NonNull; use std::sync::Arc; struct LocalAllocator { memory: NonNull<u8>, size: usize, } impl LocalAllocator { fn new(size: usize) -> Self { Self { memory: unsafe { NonNull::new_unchecked(&mut 0u8 as *mut u8) }, size, } } } unsafe impl Allocator for LocalAllocator { fn allocate(&self, _layout: Layout) -> Result<NonNull<[u8]>, AllocError> { Ok(NonNull::slice_from_raw_parts(self.memory, self.size)) } unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: Layout) { } } fn main() { let allocator = LocalAllocator::new(64); let arc = Arc::new_in(5, &allocator); // Here, allocator could be any non-global allocator let ptr = Arc::into_raw(arc); unsafe { Arc::increment_strong_count(ptr); let arc = Arc::from_raw(ptr); assert_eq!(2, Arc::strong_count(&arc)); // Failed here! } } ```
2025-01-16fix typo in library/alloc/src/sync.rsClearLove-1/+1
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-15Update compiler-builtins to 0.1.143Trevor Gross-1/+1
0.1.142 fixes an issue parsing optimization flags, and 0.1.143 changes `__rust_[ui]128_*` builtins to use a C-safe signature.
2025-01-14Update compiler-builtins to 0.1.141Trevor Gross-1/+1
0.1.141 syncs changes from `libm`. Most of the `libm` changes are testing- or configuration-related.
2025-01-14Rollup merge of #135381 - cod10129:vec-splice-doc, r=tgross35Matthias Krüger-3/+13
Add an example for `Vec::splice` inserting elements without removing This example clearly showcases how `splice` can be used to insert multiple elements efficiently at an index into a vector. Fixes #135369. The added example: > Using `splice` to insert new items into a vector efficiently at a specific position indicated by an empty range: > ```rust > let mut v = vec![1, 5]; > let new = [2, 3, 4]; > v.splice(1..1, new); > assert_eq!(v, [1, 2, 3, 4, 5]); > ``` `@rustbot` label A-docs A-collections
2025-01-13Add another `Vec::splice` examplecod10129-3/+13
Add an example for using splice to insert multiple elements efficiently into a vector.
2025-01-12Update the explanation for why we use box_new in vec!Ben Kimock-2/+2
2025-01-12Auto merge of #135402 - matthiaskrgr:rollup-cz7hs13, r=matthiaskrgrbors-3/+1
Rollup of 6 pull requests Successful merges: - #129259 (Add inherent versions of MaybeUninit methods for slices) - #135374 (Suggest typo fix when trait path expression is typo'ed) - #135377 (Make MIR cleanup for functions with impossible predicates into a real MIR pass) - #135378 (Remove a bunch of diagnostic stashing that doesn't do anything) - #135397 (compiletest: add erroneous variant to `string_enum`s conversions error) - #135398 (add more crash tests) r? `@ghost` `@rustbot` modify labels: rollup
2025-01-12Omit some more `From` impls to avoid inference failuresJosh Triplett-65/+54
2025-01-11Add inherent versions of MaybeUninit methods for slicesltdk-3/+1
2025-01-11Make UniqueRc invariant for soundnessFrank Steffahn-2/+6
2025-01-11Rollup merge of #135347 - samueltardieu:push-qvyxtxsqyxyr, r=jhprattJacob Pratt-24/+7
Use `NonNull::without_provenance` within the standard library This API removes the need for several `unsafe` blocks, and leads to clearer code. It uses feature `nonnull_provenance` (#135243). Close #135343
2025-01-11Rollup merge of #135236 - scottmcm:more-mcp807-library-updates, r=ChrisDentonJacob Pratt-24/+23
Update a bunch of library types for MCP807 This greatly reduces the number of places that actually use the `rustc_layout_scalar_valid_range_*` attributes down to just 3: ``` library/core\src\ptr\non_null.rs 68:#[rustc_layout_scalar_valid_range_start(1)] library/core\src\num\niche_types.rs 19: #[rustc_layout_scalar_valid_range_start($low)] 20: #[rustc_layout_scalar_valid_range_end($high)] ``` Everything else -- PAL Nanoseconds, alloc's `Cap`, niched FDs, etc -- all just wrap those `niche_types` types. r? ghost
2025-01-11Support `no_rc`, `no_sync`, and `no_global_oom_handling`Josh Triplett-0/+9
For now, apply `no_global_oom_handling` to all of library/alloc/src/bstr.rs . We can make it more fine-grained later.
2025-01-11Add `#[cfg(not(test))]` to some impls to work around ↵Josh Triplett-0/+20
https://github.com/rust-lang/rust/issues/135100
2025-01-11Implement `ByteStr` and `ByteString` typesJosh Triplett-0/+687
Approved ACP: https://github.com/rust-lang/libs-team/issues/502 Tracking issue: https://github.com/rust-lang/rust/issues/134915 These types represent human-readable strings that are conventionally, but not always, UTF-8. The `Debug` impl prints non-UTF-8 bytes using escape sequences, and the `Display` impl uses the Unicode replacement character. This is a minimal implementation of these types and associated trait impls. It does not add any helper methods to other types such as `[u8]` or `Vec<u8>`. I've omitted a few implementations of `AsRef`, `AsMut`, `Borrow`, `From`, and `PartialOrd`, when those would be the second implementation for a type (counting the `T` impl) or otherwise may cause inference failures. These impls are important, but we can attempt to add them later in standalone commits, and run them through crater. In addition to the `bstr` feature, I've added a `bstr_internals` feature for APIs provided by `core` for use by `alloc` but not currently intended for stabilization. This API and its implementation are based *heavily* on the `bstr` crate by Andrew Gallant (@BurntSushi).
2025-01-10Use `NonNull::without_provenance` within the standard librarySamuel Tardieu-24/+7
This API removes the need for several `unsafe` blocks, and leads to clearer code.
2025-01-10alloc: remove unsound `IsZero` for raw pointersjoboet-13/+12
Fixes #135338
2025-01-09Update a bunch of library types for MCP807Scott McMurray-24/+23
This greatly reduces the number of places that actually use the `rustc_layout_scalar_valid_range_*` attributes down to just 3: ``` library/core\src\ptr\non_null.rs 68:#[rustc_layout_scalar_valid_range_start(1)] library/core\src\num\niche_types.rs 19: #[rustc_layout_scalar_valid_range_start($low)] 20: #[rustc_layout_scalar_valid_range_end($high)] ``` Everything else -- PAL Nanoseconds, alloc's `Cap`, niched FDs, etc -- all just wrap those `niche_types` types.
2025-01-09Auto merge of #135268 - pietroalbini:pa-bump-stage0, r=Mark-Simulacrumbors-7/+3
Master bootstrap update Part of the release process. r? `@Mark-Simulacrum`
2025-01-08Remove some unnecessary `.into()` callsEsteban Küber-2/+2
2025-01-08update cfg(bootstrap)Pietro Albini-7/+3
2025-01-08update version placeholdersPietro Albini-3/+3
2025-01-08Rollup merge of #133057 - tisonkun:into-chars, r=AmanieuJacob Pratt-2/+185
Impl String::into_chars Tracking issue - https://github.com/rust-lang/rust/issues/133125 r? `@programmerjake` `@kennytm` `@Amanieu` This refers to https://github.com/rust-lang/libs-team/issues/268 Before adding tests and creating a tracking issue, I'd like to reach a consensus on the implementation direction and two questions: 1. Whether we'd add a `String::into_char_indices` method also? 2. See inline comment.
2025-01-04Rollup merge of #135104 - the8472:disable-in-place-iter-for-flatten, ↵Jubilee-19/+20
r=Mark-Simulacrum do not in-place-iterate over flatmap/flatten The implementation is unsound when a partially consumed iterator has some elements buffered in the front/back parts and cloning the Iterator removes the capacity from the backing vec::IntoIter. This is a fix for #135103 that removes the specialization trait impls without removing some supporting parts. I've kept it small so it can be easily backported. I'll either remove the remaining parts or think of a way to recover the optimization in a separate PR.