summary refs log tree commit diff
path: root/library/alloc
AgeCommit message (Collapse)AuthorLines
2024-03-11Rollup merge of #122298 - RalfJung:raw-vec-into-box, r=cuviperJacob Pratt-2/+1
RawVec::into_box: avoid unnecessary intermediate reference Fixes the problem described [here](https://github.com/rust-lang/miri/issues/3341#issuecomment-1987207195).
2024-03-11Rollup merge of #121148 - clarfonthey:try-range, r=dtolnayJacob Pratt-2/+2
Add slice::try_range This adds a fallible version of the unstable `slice::range` (tracking: #76393) which is highly requested in the tracking issue. Hoping this can slide by without an ACP (since the feature is already being tracked), but let me know otherwise.
2024-03-10RawVec::into_box: avoid unnecessary intermediate referenceRalf Jung-2/+1
2024-03-10Rollup merge of #112136 - clarfonthey:ffi-c_str, r=cuviperMatthias Krüger-3/+9
Add std::ffi::c_str module ACP: rust-lang/libs-team#134 `std::ffi` docs before change: ![Structs: VaList, VaListImpl, CStr, CString, FromBytesWithNulError, FromVecWithNulError, IntoStringError, NulError, OsStr, OsString](https://github.com/rust-lang/rust/assets/15850505/b2cf3534-30f9-4ef0-a655-bacdc3a19e17) `std::ffi` docs after change: ![Re-exports: self::c_str::{FromBytesWithNulError, FromBytesUntilNulError, FromVecWithNulError, NulError, IntoStringError} ; Modules: c_str ; Structs: VaList, VaListImpl, CStr, CString, OsStr, OsString](https://github.com/rust-lang/rust/assets/15850505/23aa6964-da7a-4942-bbf7-42bde2146f9e) (note: I'm omitting the `c_int`, etc. stuff from the screenshots since it's the same in both. this doesn't just delete those types)
2024-03-09Rollup merge of #120504 - kornelski:try_with_capacity, r=AmanieuGuillaume Boisseau-26/+149
Vec::try_with_capacity Related to #91913 Implements try_with_capacity for `Vec`, `VecDeque`, and `String`. I can follow it up with more collections if desired. `Vec::try_with_capacity()` is functionally equivalent to the current stable: ```rust let mut v = Vec::new(); v.try_reserve_exact(n)? ``` However, `try_reserve` calls non-inlined `finish_grow`, which requires old and new `Layout`, and is designed to reallocate memory. There is benefit to using `try_with_capacity`, besides syntax convenience, because it generates much smaller code at the call site with a direct call to the allocator. There's codegen test included. It's also a very desirable functionality for users of `no_global_oom_handling` (Rust-for-Linux), since it makes a very commonly used function available in that environment (`with_capacity` is used much more frequently than all `(try_)reserve(_exact)`).
2024-03-09miri: do not apply aliasing restrictions to Box with custom allocatorRalf Jung-10/+14
2024-03-08Rollup merge of #122099 - Urgau:btreemap-inline-new, r=AmanieuMatthias Krüger-0/+1
Add `#[inline]` to `BTreeMap::new` constructor This PR add the `#[inline]` attribute to `BTreeMap::new` constructor as to make it eligible for inlining. <details> For some context: I was profiling `rustc --check-cfg` with callgrind and due to the way we currently setup all the targets and we end-up calling `BTreeMap::new` multiple times for (nearly) all the targets. Adding the `#[inline]` attribute reduced the number of instructions needed. </details>
2024-03-07Rust is a proper name: rust → RustRalf Jung-1/+1
2024-03-06Add #[inline] to BTreeMap::new constructorUrgau-0/+1
2024-03-05Rollup merge of #122018 - RalfJung:box-custom-alloc, r=oli-obkMatthias Krüger-0/+5
only set noalias on Box with the global allocator As discovered in https://github.com/rust-lang/miri/issues/3341, `noalias` and custom allocators don't go well together. rustc can now check whether a Box uses the global allocator. This replaces the previous ad-hoc and rather unprincipled check for a zero-sized allocator. This is the rustc part of fixing that; Miri will also need a patch.
2024-03-05Rollup merge of #122016 - RalfJung:will_wake, r=dtolnayMatthias Krüger-0/+2
will_wake tests fail on Miri and that is expected Follow-up to https://github.com/rust-lang/rust/pull/121622 r? ```@cuviper``` ```@dtolnay```
2024-03-05Rollup merge of #121894 - RalfJung:const_eval_select, r=oli-obkMatthias Krüger-0/+1
const_eval_select: make it safe but be careful with what we expose on stable for now As this is all still nightly-only I think `````@rust-lang/wg-const-eval````` can do that without involving t-lang. r? `````@oli-obk````` Cc `````@Nilstrieb````` -- the updated version of your RFC would basically say that we can remove these comments about not making behavior differences visible in stable `const fn`
2024-03-05only set noalias on Box with the global allocatorRalf Jung-0/+5
2024-03-05will_wake tests fail on Miri and that is expectedRalf Jung-0/+2
2024-03-05Rollup merge of #121287 - zachs18:rc-into-raw-must-use, r=cuviperMatthias Krüger-2/+3
Clarify/add `must_use` message for Rc/Arc/Weak::into_raw. The current `#[must_use]` messages for `{sync,rc}::Weak::into_raw` ("`self` will be dropped if the result is not used") are misleading, as `self` is consumed and will *not* be dropped. This PR changes their `#[must_use]` message to the same as `Arc::into_raw`'s[ current `#[must_use]` message](https://github.com/rust-lang/rust/blob/d5735645753e990a72446094f703df9b5e421555/library/alloc/src/sync.rs#L1482) ("losing the pointer will leak memory"), and also adds it to `Rc::into_raw`, which is not currently `#[must_use]`.
2024-03-05Rollup merge of #121262 - 20jasper:add-vector-time-complexity, r=cuviperMatthias Krüger-0/+21
Add vector time complexity Added time complexity for `Vec` methods `push`, `push_within_capacity`, `pop`, and `insert`. <details> <summary> Reference images </summary> ![`Vec::push` documentation](https://github.com/rust-lang/rust/assets/78604367/dc966bbd-e92e-45a6-af82-35afabfa79a9) ![`Vec::push_within_capacity` documentation](https://github.com/rust-lang/rust/assets/78604367/9aadaf48-46ed-4fad-bdd5-74b98a61f4bb) ![`Vec::pop` documentation](https://github.com/rust-lang/rust/assets/78604367/88ec0389-a346-4ea5-a3b7-17caf514dd8b) ![`Vec::insert` documentation](https://github.com/rust-lang/rust/assets/78604367/960c15c3-ef8e-4aa7-badc-35ce80f6f221) </details> I followed a convention to use `#Time complexity` that I found in [the `BinaryHeap` documentation](https://doc.rust-lang.org/std/collections/struct.BinaryHeap.html#time-complexity-1). Looking through the rest of standard library collections, there is not a consistent way to handle this. [`Vec::swap_remove`](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.swap_remove) does not have a dedicated section for time complexity but does list it. [`VecDeque::rotate_left`](https://doc.rust-lang.org/std/collections/struct.VecDeque.html#complexity) uses a `#complexity` heading.
2024-03-05Rollup merge of #121213 - Takashiidobe:takashi/example-for-rc-into-inner, ↵Matthias Krüger-0/+15
r=cuviper Add an example to demonstrate how Rc::into_inner works This PR adds an example to Rc::into_inner, since it didn't have one previously.
2024-03-02Rollup merge of #121622 - dtolnay:wake, r=cuviperGuillaume Boisseau-0/+49
Preserve same vtable pointer when cloning raw waker, to fix Waker::will_wake Fixes #121600. As `@jkarneges` identified in https://github.com/rust-lang/rust/issues/121600#issuecomment-1963041051, the issue is two different const promotions produce two statics at different addresses, which may or may not later be deduplicated by the linker (in this case not). Prior to #119863, the content of the statics was compared, and they were equal. After, the address of the statics are compared and they are not equal. It is documented that `will_wake` _"works on a best-effort basis, and may return false even when the Wakers would awaken the same task"_ so this PR fixes a quality-of-implementation issue, not a correctness issue.
2024-03-02const_eval_select: make it safe but be careful with what we expose on stable ↵Ralf Jung-0/+1
for now
2024-03-01Move capacity_overflow function to make ui tests change lessKornel-9/+9
Code changes in raw_vec require blessing UI tests every time
2024-03-01try_with_capacity for Vec, VecDeque, StringKornel-0/+116
#91913
2024-03-01try_with_capacity for RawVecKornel-18/+25
2024-03-01remove hidden use of GlobalAlexander-1/+1
2024-02-29Rollup merge of #120291 - pitaj:string-sliceindex, r=AmanieuJacob Pratt-88/+15
Have `String` use `SliceIndex` impls from `str` This PR simplifies the implementation of `Index` and `IndexMut` on `String`, and in the process enables indexing `String` by any user types that implement `SliceIndex<str>`. Similar to #47832 r? libs Not sure if this warrants a crater run.
2024-02-27have `String` use `SliceIndex` impls from `str`Peter Jaszkowiak-88/+15
2024-02-26Generate original vtable and clone's vtable in the same CGUDavid Tolnay-0/+13
2024-02-26Document args returned from `String::into_raw_parts`许杰友 Jieyou Xu (Joe)-1/+1
2024-02-26Document args returned from `Vec::into_raw_parts{,_with_alloc}`许杰友 Jieyou Xu (Joe)-2/+2
2024-02-26Rearrange `String::from_raw_parts` doc argument order to match code argument ↵许杰友 Jieyou Xu (Joe)-1/+1
order
2024-02-26Rearrange `Vec::from_raw_parts{,_in}` doc argument order to match code ↵许杰友 Jieyou Xu (Joe)-2/+2
argument order
2024-02-25Add Waker::will_wake testsDavid Tolnay-0/+36
Currently fails: ---- task::test_waker_will_wake_clone stdout ---- thread 'task::test_waker_will_wake_clone' panicked at library/alloc/tests/task.rs:17:5: assertion failed: waker.will_wake(&clone)
2024-02-25Make push docs more vagueJacob Asper-4/+3
2024-02-24Rollup merge of #121556 - GrigorenkoPV:addr_of, r=NilstriebMatthias Krüger-5/+5
Use `addr_of!` As per https://github.com/rust-lang/rust/pull/121303#discussion_r1500954662
2024-02-24Forbid use of `extern "C-unwind"` inside standard libraryGary Guo-0/+1
Those libraries are build with `-C panic=unwind` and is expected to be linkable to `-C panic=abort` library. To ensure unsoundness compiler needs to prevent a `C-unwind` call to exist, as doing so may leak foreign exceptions into `-C panic=abort`.
2024-02-24library: use `addr_of!`Pavel Grigorenko-5/+5
2024-02-23Auto merge of #121514 - matthiaskrgr:rollup-5f0vhv7, r=matthiaskrgrbors-6/+6
Rollup of 6 pull requests Successful merges: - #120742 (mark `min_exhaustive_patterns` as complete) - #121470 (Don't ICE on anonymous struct in enum variant) - #121492 (coverage: Rename `is_closure` to `is_hole`) - #121495 (remove repetitive words) - #121498 (Make QNX/NTO specific "timespec capping" public to crate::sys) - #121510 (lint-overflowing-ops: unify cases and remove redundancy) r? `@ghost` `@rustbot` modify labels: rollup
2024-02-23Auto merge of #121454 - reitermarkus:generic-nonzero-library, r=dtolnaybors-41/+28
Use generic `NonZero` everywhere in `library`. Tracking issue: https://github.com/rust-lang/rust/issues/120257 Use generic `NonZero` everywhere (except stable examples). r? `@dtolnay`
2024-02-23remove repetitive wordscui fliter-6/+6
Signed-off-by: cui fliter <imcusg@gmail.com>
2024-02-22On type error of method call arguments, look at confusables for suggestionEsteban Küber-0/+1
2024-02-22Add `rustc_confusables` annotations to some stdlib APIsEsteban Küber-0/+34
Help with common API confusion, like asking for `push` when the data structure really has `append`. ``` error[E0599]: no method named `size` found for struct `Vec<{integer}>` in the current scope --> $DIR/rustc_confusables_std_cases.rs:17:7 | LL | x.size(); | ^^^^ | help: you might have meant to use `len` | LL | x.len(); | ~~~ help: there is a method with a similar name | LL | x.resize(); | ~~~~~~ ``` #59450
2024-02-22Use generic `NonZero` everywhere in `alloc`.Markus Reiter-41/+28
2024-02-22Add std::ffi::c_str modulesltdk-3/+9
2024-02-22Auto merge of #118634 - Jules-Bertholet:box-allocator-static, r=Amanieubors-9/+3
Remove useless `'static` bounds on `Box` allocator #79327 added `'static` bounds to the allocator parameter for various `Box` + `Pin` APIs to ensure soundness. But it was a bit overzealous, some of the bounds aren't actually needed.
2024-02-21rename ptr::invalid -> ptr::without_provenanceRalf Jung-12/+20
also introduce ptr::dangling matching NonNull::dangling
2024-02-18Clarify/add `must_use` message for Rc/Arc/Weak::into_raw.Zachary S-2/+3
2024-02-18Fix error in push docsJacob Asper-4/+5
Copying is O(n)—not the memory allocation
2024-02-18Rollup merge of #121224 - hi-rustin:rustin-patch-unit-binding, r=Mark-SimulacrumMatthias Krüger-2/+2
Remove unnecessary unit binding It appears that the unit binding is not necessary at this time. However, I am unsure of its importance in the past. Please let me know if it is unsafe to remove.
2024-02-18fix typo in push documentationJacob Asper-1/+1
2024-02-18intradoc link for vecJacob Asper-1/+1
2024-02-18time complexity for insertJacob Asper-0/+6