about summary refs log tree commit diff
path: root/library/alloc/src/vec
AgeCommit message (Collapse)AuthorLines
2025-04-20Implement lint against dangerous implicit autorefsUrgau-1/+1
2025-04-09replace version placeholderBoxy-12/+12
2025-04-08document panic behavior of Vec::resize and Vec::resize_withJonathan Gruner-0/+8
2025-03-30Delete unreacheable `#[rustc_on_unimplemented]`mejrs-8/+0
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-09document capacity for ZST as example and proseMarijn Schouten-0/+13
2025-03-08Stabilize `const_vec_string_slice`Martin Habovstiak-7/+7
This feature was approved for stabilization in https://github.com/rust-lang/rust/issues/129041#issuecomment-2508940661 so this change stabilizes it.
2025-03-07Fully test the alloc crate through alloctestsbjorn3-43/+9
For the tests that make use of internal implementation details, we include the module to test using #[path] in alloctests now.
2025-03-06library: Use size_of from the prelude instead of importedThalia Archibald-17/+17
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-02-24Rollup merge of #137109 - bend-n:knife, r=oli-obkTrevor Gross-9/+5
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 #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-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-9/+5
2025-02-21Explain how Vec::with_capacity is faithfulMarijn Schouten-5/+17
Co-authored-by: Jubilee <workingjubilee@gmail.com> and jmaargh
2025-02-18update version placeholdersJosh Stone-1/+1
(cherry picked from commit e4840ce59bdddb19394df008c5c26d9c493725f8)
2025-02-13alloc: Apply missing_unsafe_on_externEric Huss-1/+1
2025-02-09Rollup merge of #135488 - GrigorenkoPV:vec_pop_if, r=jhprattMatthias Krüger-3/+1
Stabilize `vec_pop_if` Tracking issue: #122741 FCP completed in https://github.com/rust-lang/rust/issues/122741#issuecomment-2605116387
2025-01-25[Clippy] Add vec_reserve & vecdeque_reserve diagnostic itemswowinter13-0/+1
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-25Stabilize `vec_pop_if`Pavel Grigorenko-3/+1
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-24Doc difference between extend and extend_from_sliceMarijn Schouten-4/+3
fixes #97119
2025-01-24Make `Vec::pop_if` a bit more presentablePavel Grigorenko-7/+4
2025-01-19Fix whitespaceMarijn Schouten-1/+1
2025-01-19document order of items in iterator from drainMarijn Schouten-3/+5
fixes 135710
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-10alloc: remove unsound `IsZero` for raw pointersjoboet-13/+2
Fixes #135338
2024-12-22Auto merge of #131193 - EFanZh:asserts-vec-len, r=the8472bors-2/+9
Asserts the maximum value that can be returned from `Vec::len` Currently, casting `Vec<i32>` to `Vec<u32>` takes O(1) time: ```rust // See <https://godbolt.org/z/hxq3hnYKG> for assembly output. pub fn cast(vec: Vec<i32>) -> Vec<u32> { vec.into_iter().map(|e| e as _).collect() } ``` But the generated assembly is not the same as the identity function, which prevents us from casting `Vec<Vec<i32>>` to `Vec<Vec<u32>>` within O(1) time: ```rust // See <https://godbolt.org/z/7n48bxd9f> for assembly output. pub fn cast(vec: Vec<Vec<i32>>) -> Vec<Vec<u32>> { vec.into_iter() .map(|e| e.into_iter().map(|e| e as _).collect()) .collect() } ``` This change tries to fix the problem. You can see the comparison here: <https://godbolt.org/z/jdManrKvx>.
2024-12-20Rollup merge of #126118 - jan-ferdinand:docs_for_vec_set_len, r=the8472Jacob Pratt-1/+6
docs: Mention `spare_capacity_mut()` in `Vec::set_len` I recently went down a small rabbit hole when trying to identify safe use of `Vec::set_len`. The solution was `Vec::spare_capacity_mut`. I think the docs on `Vec::set_len` benefit from mentioning this method. A possible counter-argument could be that the [clippy lint `uninit_vec`](https://rust-lang.github.io/rust-clippy/master/index.html#/uninit_vec) already nudges people in the right direction. However, I think a working example on `Vec::set_len` is still beneficial. Happy to hear your thoughts on the matter. :blush:
2024-12-16remove obsolete comment and pub(super) visibilityThe 8472-12/+6
2024-12-16remove bounds from vec and linkedlist ExtractIfThe 8472-12/+5
since drain-on-drop behavior was removed those bounds no longer serve a purpose
2024-12-16Add a range argument to vec.extract_ifThe 8472-20/+46
2024-12-15Asserts the maximum value that can be returned from `Vec::len`EFanZh-2/+9
2024-12-14Replace i32 by char to add claritytkirishima-14/+14
In some `Vec` and `VecDeque` examples where elements are i32, examples can seem a bit confusing at first glance if a parameter of the method is an usize.
2024-12-05Improve documentationXelph-11/+14
Fix missing newlines that rustfmt removed. fix trailing whitespace Fix duplicate word. Reformat panic reasons into a list remove trailing whitespace 2 electric boogaloo Change verbe tense. Integrate suggestions
2024-11-29Auto merge of #133533 - BoxyUwU:bump-boostrap, r=jieyouxu,Mark-Simulacrumbors-2/+2
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-28Also use zero when referencing to capacity or lengthtimvisee-4/+4
2024-11-27update cfgsBoxy-2/+2
2024-11-11Tag relevant functions with #[rustc_as_ptr] attributegavincrawford-0/+2
2024-10-25library: consistently use American spelling for 'behavior'Ralf Jung-1/+1
2024-10-14Auto merge of #126557 - GrigorenkoPV:vec_track_caller, r=joboetbors-0/+57
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-07Rollup merge of #128399 - mammothbane:master, r=Amanieu,tgross35Stuart Cook-11/+44
liballoc: introduce String, Vec const-slicing 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`. ## Motivation This is to support simultaneous variance over ownership and constness. I have an enum type that may contain either `String` or `&str`, and I want to produce a `&str` from it in a possibly-`const` context. ```rust enum StrOrString<'s> { Str(&'s str), String(String), } impl<'s> StrOrString<'s> { const fn as_str(&self) -> &str { match self { // In a const-context, I really only expect to see this variant, but I can't switch the implementation // in some mode like #[cfg(const)] -- there has to be a single body Self::Str(s) => s, // so this is a problem, since it's not `const` Self::String(s) => s.as_str(), } } } ``` Currently `String` and `Vec` don't support this, but can without functional changes. Similar logic applies for `len`, `capacity`, `is_empty`. ## Changes The essential thing enabling this change is that `Unique::as_ptr` is `const`. This lets us convert `RawVec::ptr` -> `Vec::as_ptr` -> `Vec::as_slice` -> `String::as_str`. I had to move the `Deref` implementations into `as_{str,slice}` because `Deref` isn't `#[const_trait]`, but I would expect this change to be invisible up to inlining. I moved the `DerefMut` implementations as well for uniformity.
2024-10-06liballoc: introduce String, Vec const-slicingNathan Perry-11/+44
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-25Use `&raw` in the standard libraryJosh Stone-2/+2
Since the stabilization in #127679 has reached stage0, 1.82-beta, we can start using `&raw` freely, and even the soft-deprecated `ptr::addr_of!` and `ptr::addr_of_mut!` can stop allowing the unstable feature. I intentionally did not change any documentation or tests, but the rest of those macro uses are all now using `&raw const` or `&raw mut` in the standard library.
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-2/+2
2024-09-20Add `Vec::as_non_null`Tim (Theemathas) Chirananthavat-2/+69
2024-09-20Add `#[track_caller]` to allocating methods of `Vec` & `VecDeque`Pavel Grigorenko-0/+57
2024-09-19[Clippy] Swap `manual_while_let_some` to use diagnostic items instead of pathsGnomedDev-0/+2
2024-09-19[Clippy] Swap `repeat_vec_with_capacity` to use diagnostic item instead of pathGnomedDev-0/+1