about summary refs log tree commit diff
path: root/library/alloc/src/vec
AgeCommit message (Collapse)AuthorLines
2023-10-29Increase the reach of panic_immediate_abortBen Kimock-4/+7
2023-10-16Add invariant to Vec::pop that len < cap if pop successfulArthur Carcano-0/+1
Fixes: https://github.com/rust-lang/rust/issues/114334
2023-10-08Bump to latest betaMark Rousskov-2/+2
2023-10-03Bump version placeholdersMark Rousskov-2/+2
2023-09-28Auto merge of #111278 - EFanZh:implement-from-array-refs-for-vec, r=dtolnaybors-0/+30
Implement `From<{&,&mut} [T; N]>` for `Vec<T>` where `T: Clone` Currently, if `T` implements `Clone`, we can create a `Vec<T>` from an `&[T]` or an `&mut [T]`, can we also support creating a `Vec<T>` from an `&[T; N]` or an `&mut [T; N]`? Also, do I need to add `#[inline]` to the implementation? ACP: rust-lang/libs-team#220. [Accepted] Closes #100880.
2023-09-16edit `std::vec::Vec::truncate` docsmxnkarou-2/+2
2023-09-16Auto merge of #114494 - est31:extend_useless_ptr_null_checks, r=jackh726bors-0/+2
Make useless_ptr_null_checks smarter about some std functions This teaches the `useless_ptr_null_checks` lint that some std functions can't ever return null pointers, because they need to point to valid data, get references as input, etc. This is achieved by introducing an `#[rustc_never_returns_null_ptr]` attribute and adding it to these std functions (gated behind bootstrap `cfg_attr`). Later on, the attribute could maybe be used to tell LLVM that the returned pointer is never null. I don't expect much impact of that though, as the functions are pretty shallow and usually the input data is already never null. Follow-up of PR #113657 Fixes #114442
2023-08-29Auto merge of #113859 - Manishearth:vec-as-mut-ptr-stacked-borrow, r=dtolnaybors-0/+51
Add note that Vec::as_mut_ptr() does not materialize a reference to the internal buffer See discussion on https://github.com/thomcc/rust-typed-arena/issues/62 and [t-opsem](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/is.20this.20typed_arena.20code.20sound.20under.20stacked.2Ftree.20borrows.3F) This method already does the correct thing here, but it is worth guaranteeing that it does so it can be used more freely in unsafe code without having to worry about potential Stacked/Tree Borrows violations. This moves one more unsafe usage pattern from the "very likely sound but technically not fully defined" box into "definitely sound", and currently our surface area of the latter is woefully small. I'm not sure how best to word this, opening this PR as a way to start discussion.
2023-08-16Update library/alloc/src/vec/mod.rsManish Goregaokar-1/+1
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-08-16Update library/alloc/src/vec/mod.rsManish Goregaokar-1/+2
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-08-15other elementsManish Goregaokar-3/+3
2023-08-15Update library/alloc/src/vec/mod.rsManish Goregaokar-1/+1
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-08-15Update library/alloc/src/vec/mod.rsManish Goregaokar-1/+1
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-08-12aliasing guaranteeManish Goregaokar-25/+40
2023-08-06Add #[rustc_never_returns_null_ptr] to std functionsest31-0/+2
Add the attribute to standard library functions that are guaranteed to never return null pointers, as their originating data wouldn't allow it.
2023-07-29Documentation: Fix Stilted Language in Vec->IndexingRyan O'Neill-1/+1
Problem Language in the Vec->Indexing documentation sounds stilted due to incorrect word ordering: "... type allows to access values by index." Solution Reorder words in the Vec->Indexing documentation to flow better: "... type allows access to values by index." The phrase "allows access to" also matches other existing documentation.
2023-07-25Add note that Vec::as_mut_ptr() does not materialize a reference to the ↵Manish Goregaokar-0/+35
internal buffer
2023-07-22Auto merge of #113224 - zachs18:vec_extend_remove_allocator_lifetime, r=cuviperbors-3/+3
Remove lifetime bound for A for `impl Extend<&'a T> for Vec<T, A>`. The lifetime of the references being copied from is unrelated to the allocator. Compare with [`impl<'a, T: 'a + Copy, A: Allocator> Extend<&'a T> for VecDeque<T, A>`](https://doc.rust-lang.org/alloc/collections/vec_deque/struct.VecDeque.html#impl-Extend%3C%26'a+T%3E-for-VecDeque%3CT,+A%3E) which does not have the `A: 'a` bound already. Since `Allocator` is unstable, the only possible `A` on stable is `Global`, and `Global: 'static`, so this change is not (should not be) observable on stable (or without `#![feature(allocator_api)]`). [This is observable on nightly](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=8c4aa166c6116a90593d2934d30cfeb3).
2023-07-16Implement `From<{&,&mut} [T; N]>` for `Vec<T>`EFanZh-0/+30
2023-07-01Remove lifetime bound for A for `impl Extend<&'a T> for Vec<T, A>`.Zachary S-3/+3
2023-06-29Fix document examples of Vec::from_raw_parts and Vec::from_raw_parts_inLi Zhanhui-14/+15
Signed-off-by: Li Zhanhui <lizhanhui@gmail.com>
2023-06-26Rollup merge of #112677 - the8472:remove-unusued-field, r=JohnTitorTakayuki Maeda-9/+1
remove unused field Followup to #104455. The field is no longer needed since ExtractIf (previously DrainFilter) doesn't keep draining in its drop impl.
2023-06-21Rollup merge of #112632 - gootorov:vec_alloc_partialeq, r=dtolnayNilstrieb-2/+7
Implement PartialOrd for `Vec`s over different allocators It is already possible to `PartialEq` `Vec`s with different allocators, but that is not the case with `PartialOrd`.
2023-06-18alloc: Implement PartialOrd for `Vec`s over different allocatorsIgor Gutorov-2/+7
2023-06-15remove unused fieldThe 8472-9/+1
since DrainFilter no longer continues draining when it's dropped the panic tracking is no longer needed.
2023-06-14s/drain_filter/extract_if/ for Vec, Btree{Map,Set} and LinkedListThe 8472-22/+22
2023-06-14remove drain-on-drop behavior from vec::DrainFilter and add #[must_use]The 8472-91/+21
2023-06-04Remove ExtendWith and ExtendElementGrisha Vartanyan-26/+10
2023-05-24Stabilize `BuildHasher::hash_one`Scott McMurray-1/+0
2023-05-23Rollup merge of #111609 - LegionMammal978:internal-unsafe, r=thomccDylan DPC-4/+5
Mark internal functions and traits unsafe to reflect preconditions No semantics are changed in this PR; I only mark some functions and and a trait `unsafe` which already had implicit preconditions. Although it seems somewhat redundant for `numfmt::Part::Copy` to contain a `&[u8]` instead of a `&str`, given that all of its current consumers ultimately expect valid UTF-8. Is the type also intended to work for byte-slice formatting in the future?
2023-05-15Mark internal functions and traits unsafeLegionMammal978-4/+5
2023-05-15Change Vec examples to not assert exact capacity except where it is guaranteedWim Looman-6/+6
2023-05-08Auto merge of #106621 - ozkanonur:enable-elided-lifetimes-for-doctests, ↵bors-5/+5
r=Mark-Simulacrum enable `rust_2018_idioms` lint group for doctests With this change, `rust_2018_idioms` lint group will be enabled for compiler/libstd doctests. Resolves #106086 Resolves #99144 Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-05-07enable `rust_2018_idioms` for doctestsozkanonur-5/+5
Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-04-28replace version placeholdersPietro Albini-1/+1
2023-04-26Rollup merge of #110419 - jsoref:spelling-library, r=jyn514Matthias Krüger-1/+1
Spelling library Split per https://github.com/rust-lang/rust/pull/110392 I can squash once people are happy w/ the changes. It's really uncommon for large sets of changes to be perfectly acceptable w/o at least some changes. I probably won't have time to respond until tomorrow or the next day
2023-04-26Spelling library/Josh Soref-1/+1
* advance * aligned * borrowed * calculate * debugable * debuggable * declarations * desugaring * documentation * enclave * ignorable * initialized * iterator * kaboom * monomorphization * nonexistent * optimizer * panicking * process * reentrant * rustonomicon * the * uninitialized Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-22Rollup merge of #110635 - scottmcm:zst-checks, r=the8472Yuki Okushi-7/+3
More `IS_ZST` in `library` I noticed that `post_inc_start` and `pre_dec_end` were doing this check in different ways https://github.com/rust-lang/rust/blob/d19b64fb54391b64ce99981577c67c93ac2a9ffa/library/core/src/slice/iter/macros.rs#L76-L93 so started making this PR, then added a few more I found since I was already making changes anyway.
2023-04-21More `IS_ZST` in `library`Scott McMurray-7/+3
I noticed that `post_inc_start` and `pre_dec_end` were doing this check in different ways https://github.com/rust-lang/rust/blob/d19b64fb54391b64ce99981577c67c93ac2a9ffa/library/core/src/slice/iter/macros.rs#L76-L93 so started making this PR, then added a few more I found since I was already making changes anyway.
2023-04-20More `mem::take` in `library`Scott McMurray-1/+1
A bunch of places were using `replace(…, &mut [])`, but that can just be `take`.
2023-04-16rm const traits in libcoreDeadbeef-2/+1
2023-04-12remove some unneeded importsKaDiWa-7/+3
2023-03-27replace advance_by returning usize with Result<(), NonZeroUsize>The 8472-4/+5
2023-03-27Change advance(_back)_by to return `usize` instead of `Result<(), usize>`The 8472-10/+4
A successful advance is now signalled by returning `0` and other values now represent the remaining number of steps that couldn't be advanced as opposed to the amount of steps that have been advanced during a partial advance_by. This simplifies adapters a bit, replacing some `match`/`if` with arithmetic. Whether this is beneficial overall depends on whether `advance_by` is mostly used as a building-block for other iterator methods and adapters or whether we also see uses by users where `Result` might be more useful.
2023-03-25Auto merge of #99929 - the8472:default-iters, r=scottmcmbors-0/+18
Implement Default for some alloc/core iterators Add `Default` impls to the following collection iterators: * slice::{Iter, IterMut} * binary_heap::IntoIter * btree::map::{Iter, IterMut, Keys, Values, Range, IntoIter, IntoKeys, IntoValues} * btree::set::{Iter, IntoIter, Range} * linked_list::IntoIter * vec::IntoIter and these adapters: * adapters::{Chain, Cloned, Copied, Rev, Enumerate, Flatten, Fuse, Rev} For iterators which are generic over allocators it only implements it for the global allocator because we can't conjure an allocator from nothing or would have to turn the allocator field into an `Option` just for this change. These changes will be insta-stable. ACP: https://github.com/rust-lang/libs-team/issues/77
2023-03-21Auto merge of #106967 - saethlin:remove-vec-as-ptr-assume, r=thomccbors-11/+2
Remove the assume(!is_null) from Vec::as_ptr At a guess, this code is leftover from LLVM was worse at keeping track of the niche information here. In any case, we don't need this anymore: Removing this `assume` doesn't get rid of the `nonnull` attribute on the return type.
2023-02-28Support allocators in various Default for IntoIter implsThe 8472-2/+5
Global implements Default so we can use that as bound for all allocators
2023-02-28rewrite iterator `Default` tests as doctestsThe 8472-0/+8
2023-02-28Implement Default for some alloc/core iteratorsThe 8472-0/+7
This way one can `mem::take()` them out of structs or #[derive(Default)] on structs containing them. These changes will be insta-stable.
2023-02-27Remove or justify use of #[rustc_box]Ben Kimock-4/+1