about summary refs log tree commit diff
path: root/library/alloc/src/raw_vec.rs
AgeCommit message (Collapse)AuthorLines
2025-03-07Move all alloc integration tests to a new alloctests cratebjorn3-818/+0
2025-03-06library: Use size_of from the prelude instead of importedThalia Archibald-2/+2
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-01-20alloc: add `#![warn(unreachable_pub)]`Urgau-20/+24
2025-01-09Update a bunch of library types for MCP807Scott McMurray-24/+22
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.
2024-12-29fix: typoscalciumbe-1/+1
Signed-off-by: calciumbe <192480234+calciumbe@users.noreply.github.com>
2024-11-29Auto merge of #133533 - BoxyUwU:bump-boostrap, r=jieyouxu,Mark-Simulacrumbors-3/+0
Bump boostrap compiler to new beta Currently failing due to something about the const stability checks and `panic!`. I'm not sure why though since I wasn't able to see any PRs merged in the past few days that would result in a `cfg(bootstrap)` that shouldn't be removed. cc `@RalfJung` #131349
2024-11-28Share inline(never) generics across cratesMark Rousskov-1/+3
This reduces code sizes and better respects programmer intent when marking inline(never). Previously such a marking was essentially ignored for generic functions, as we'd still inline them in remote crates.
2024-11-27update cfgsBoxy-3/+0
2024-10-25Re-do recursive const stability checksRalf Jung-3/+3
Fundamentally, we have *three* disjoint categories of functions: 1. const-stable functions 2. private/unstable functions that are meant to be callable from const-stable functions 3. functions that can make use of unstable const features This PR implements the following system: - `#[rustc_const_stable]` puts functions in the first category. It may only be applied to `#[stable]` functions. - `#[rustc_const_unstable]` by default puts functions in the third category. The new attribute `#[rustc_const_stable_indirect]` can be added to such a function to move it into the second category. - `const fn` without a const stability marker are in the second category if they are still unstable. They automatically inherit the feature gate for regular calls, it can now also be used for const-calls. Also, several holes in recursive const stability checking are being closed. There's still one potential hole that is hard to avoid, which is when MIR building automatically inserts calls to a particular function in stable functions -- which happens in the panic machinery. Those need to *not* be `rustc_const_unstable` (or manually get a `rustc_const_stable_indirect`) to be sure they follow recursive const stability. But that's a fairly rare and special case so IMO it's fine. The net effect of this is that a `#[unstable]` or unmarked function can be constified simply by marking it as `const fn`, and it will then be const-callable from stable `const fn` and subject to recursive const stability requirements. If it is publicly reachable (which implies it cannot be unmarked), it will be const-unstable under the same feature gate. Only if the function ever becomes `#[stable]` does it need a `#[rustc_const_unstable]` or `#[rustc_const_stable]` marker to decide if this should also imply const-stability. Adding `#[rustc_const_unstable]` is only needed for (a) functions that need to use unstable const lang features (including intrinsics), or (b) `#[stable]` functions that are not yet intended to be const-stable. Adding `#[rustc_const_stable]` is only needed for functions that are actually meant to be directly callable from stable const code. `#[rustc_const_stable_indirect]` is used to mark intrinsics as const-callable and for `#[rustc_const_unstable]` functions that are actually called from other, exposed-on-stable `const fn`. No other attributes are required.
2024-10-14Auto merge of #126557 - GrigorenkoPV:vec_track_caller, r=joboetbors-0/+17
Add `#[track_caller]` to allocating methods of `Vec` & `VecDeque` Part 4 in a lengthy saga. r? `@joshtriplett` because they were the reviewer the last 3 times. `@bors` rollup=never "[just in case this has perf effects, Vec is hot](https://github.com/rust-lang/rust/pull/79323#issuecomment-731866746)" This was first attempted in #79323 by `@nvzqz.` It got approval from `@joshtriplett,` but rotted with merge conflicts and got closed. Then it got picked up by `@Dylan-DPC-zz` in #83359. A benchmark was run[^perf], the results (after a bit of thinking[^thinking]) were deemed ok[^ok], but there was a typo[^typo] and the PR was made from a wrong remote in the first place[^remote], so #83909 was opened instead. By the time #83909 rolled around, the methods in question had received some optimizations[^optimizations], so another perf run was conducted[^perf2]. The results were ok[^ok2]. There was a suggestion to add regression tests for panic behavior [^tests], but before it could be addressed, the PR fell victim to merge conflicts[^conflicts] and died again[^rip]. 3 years have passed, and (from what I can tell) this has not been tried again, so here I am now, reviving this old effort. Given how much time has passed and the fact that I've also touched `VecDeque` this time, it probably makes sense to `@bors` try `@rust-timer` [^perf]: https://github.com/rust-lang/rust/pull/83359#issuecomment-804450095 [^thinking]: https://github.com/rust-lang/rust/pull/83359#issuecomment-805286704 [^ok]: https://github.com/rust-lang/rust/pull/83359#issuecomment-812739031 [^typo]: https://github.com/rust-lang/rust/pull/83359#issuecomment-812750205 [^remote]: https://github.com/rust-lang/rust/pull/83359#issuecomment-814067119 [^optimizations]: https://github.com/rust-lang/rust/pull/83909#issuecomment-813736593 [^perf2]: https://github.com/rust-lang/rust/pull/83909#issuecomment-813825552 [^ok2]: https://github.com/rust-lang/rust/pull/83909#issuecomment-813831341 [^tests]: https://github.com/rust-lang/rust/pull/83909#issuecomment-825788964 [^conflicts]: https://github.com/rust-lang/rust/pull/83909#issuecomment-851173480 [^rip]: https://github.com/rust-lang/rust/pull/83909#issuecomment-873569771
2024-10-06liballoc: introduce String, Vec const-slicingNathan Perry-6/+6
This change `const`-qualifies many methods on Vec and String, notably `as_slice`, `as_str`, `len`. These changes are made behind the unstable feature flag `const_vec_string_slice` with the following tracking issue: https://github.com/rust-lang/rust/issues/129041
2024-09-20Add `#[track_caller]` to allocating methods of `Vec` & `VecDeque`Pavel Grigorenko-0/+17
2024-09-08add FIXME(const-hack)Ralf Jung-14/+1
2024-08-14apply #[optimize(size)] to #[cold] ones and part of the panick machineryThe 8472-0/+1
2024-08-09Add an optimizer hint for the capacity that with_capacity_in returnsBen Kimock-1/+7
2024-08-09Hoist IS_ZST check out of RawVecInner::from_*_inBen Kimock-6/+15
2024-08-09Polymorphize RawVecBen Kimock-193/+361
2024-07-29Reformat `use` declarations.Nicholas Nethercote-2/+1
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-26Fix doc nitsJohn Arundel-3/+3
Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits. https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-07-01Avoid MIR bloat in inliningScott McMurray-0/+17
In 126578 we ended up with more binary size increases than expected. This change attempts to avoid inlining large things into small things, to avoid that kind of increase, in cases when top-down inlining will still be able to do that inlining later.
2024-04-12Avoid more NonNull-raw-NonNull roundtrips in VecBen Kimock-0/+11
2024-03-28Rename reserve_for_push to grow_one and fix comment.Cai Bear-3/+3
2024-03-28Remove len argument from RawVec::reserve_for_push because it's always equal ↵Cai Bear-2/+2
to capacity. Also make Vec::insert use reserve_for_push.
2024-03-27Less generic code for Vec allocationsKornel-13/+29
2024-03-10RawVec::into_box: avoid unnecessary intermediate referenceRalf Jung-2/+1
2024-03-09Rollup merge of #120504 - kornelski:try_with_capacity, r=AmanieuGuillaume Boisseau-23/+38
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-07Rust is a proper name: rust → RustRalf Jung-1/+1
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/+9
#91913
2024-03-01try_with_capacity for RawVecKornel-15/+21
2024-02-17Remove unnecessary unit bindinghi-rustin-2/+2
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2024-02-08Reduce use of NonNull::new_unchecked in library/Ben Kimock-6/+7
2024-01-13libs: use `assert_unchecked` instead of intrinsicjoboet-4/+4
2024-01-11chore: remove unnecessary blank linehi-rustin-1/+0
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-12-29Italicise "bytes" in the docs of some `Vec` methodsGurinder Singh-2/+2
because on a cursory read it's easy to miss that the limit is in terms of bytes not no. of elements. The italics should help with that.
2023-12-11add comment to RawVec::cap fieldThe 8472-0/+5
2023-12-11add more niches to rawvecThe 8472-15/+36
2023-11-05Auto merge of #117503 - kornelski:hint-try-reserved, r=workingjubileebors-4/+14
Hint optimizer about try-reserved capacity This is #116568, but limited only to the less-common `try_reserve` functions to reduce bloat in debug binaries from debug info, while still addressing the main use-case #116570
2023-11-02Hint optimizer about reserved capacityKornel-4/+14
2023-10-29Increase the reach of panic_immediate_abortBen Kimock-1/+1
2023-10-17Automatically enable cross-crate inlining for small functionsBen Kimock-0/+1
2023-07-13Eliminate ZST allocations in `Box` and `Vec`Amanieu d'Antras-10/+20
2023-04-12remove some unneeded importsKaDiWa-1/+0
2023-01-22simplify layout calculations in rawvecThe 8472-5/+12
2022-09-22Make ZST checks in core/alloc more readableScott McMurray-6/+6
There's a bunch of these checks because of special handing for ZSTs in various unsafe implementations of stuff. This lets them be `T::IS_ZST` instead of `mem::size_of::<T>() == 0` every time, making them both more readable and more terse. *Not* proposed for stabilization at this time. Would be `pub(crate)` except `alloc` wants to use it too. (And while it doesn't matter now, if we ever get something like 85836 making it a const can help codegen be simpler.)
2022-06-29alloc: fix `no_global_oom_handling` warningsMiguel Ojeda-0/+1
Rust 1.62.0 introduced a couple new `unused_imports` warnings in `no_global_oom_handling` builds, making a total of 5 warnings: ```txt warning: unused import: `Unsize` --> library/alloc/src/boxed/thin.rs:6:33 | 6 | use core::marker::{PhantomData, Unsize}; | ^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: unused import: `from_fn` --> library/alloc/src/string.rs:51:18 | 51 | use core::iter::{from_fn, FusedIterator}; | ^^^^^^^ warning: unused import: `core::ops::Deref` --> library/alloc/src/vec/into_iter.rs:12:5 | 12 | use core::ops::Deref; | ^^^^^^^^^^^^^^^^ warning: associated function `shrink` is never used --> library/alloc/src/raw_vec.rs:424:8 | 424 | fn shrink(&mut self, cap: usize) -> Result<(), TryReserveError> { | ^^^^^^ | = note: `#[warn(dead_code)]` on by default warning: associated function `forget_remaining_elements` is never used --> library/alloc/src/vec/into_iter.rs:126:19 | 126 | pub(crate) fn forget_remaining_elements(&mut self) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ ``` This patch cleans them so that projects compiling `alloc` without infallible allocations do not see the warnings. It also enables the use of `-Dwarnings`. The couple `dead_code` ones may be reverted when some fallible allocation support starts using them. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2022-05-13Remove some unnecessary `rustc_allow_const_fn_unstable` attributes.Nicholas Nethercote-1/+0
2022-04-06formattingSparkyPotato-1/+1
2022-04-06cleanupSparkyPotato-8/+2
2022-04-06fix Vec leak with 0 capacitySparkyPotato-0/+7