about summary refs log tree commit diff
path: root/library/alloc/src/vec/mod.rs
AgeCommit message (Collapse)AuthorLines
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-1/+1
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-1/+1
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-1/+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-1/+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-11/+11
2023-06-14remove drain-on-drop behavior from vec::DrainFilter and add #[must_use]The 8472-0/+6
2023-06-04Remove ExtendWith and ExtendElementGrisha Vartanyan-23/+7
2023-05-24Stabilize `BuildHasher::hash_one`Scott McMurray-1/+0
2023-05-15Change Vec examples to not assert exact capacity except where it is guaranteedWim Looman-6/+6
2023-05-07enable `rust_2018_idioms` for doctestsozkanonur-2/+2
Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-04-16rm const traits in libcoreDeadbeef-2/+1
2023-04-12remove some unneeded importsKaDiWa-5/+2
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-27Remove or justify use of #[rustc_box]Ben Kimock-4/+1
2023-02-23docs: use intra-doc links for `Vec::get(_mut)`Michael Howell-2/+2
Now that #63351 is fixed, there's no reason not to.
2023-02-19Remove the assume(!is_null) from Vec::as_ptrBen Kimock-11/+2
2023-01-28vec: Use SpecCloneIntoVec::clone_into to implement Vec::clone_fromNeil Roberts-30/+1
In the past, Vec::clone_from was implemented using slice::clone_into. The code from clone_into was later duplicated into clone_from in 8725e4c337, which is the commit that adds custom allocator support to Vec. Presumably this was done because the slice::clone_into only works for vecs with the default allocator so it would have the wrong type to clone into Vec<T, A>. Now that the clone_into implementation is moved out into a specializable trait anyway we might as well use that to share the code between the two methods.
2023-01-14Remove various double spaces in source comments.André Vennberg-2/+2
2023-01-07Document that `Vec::from_raw_parts[_in]` must be given a pointer from the ↵Kevin Reid-0/+5
correct allocator.
2022-12-30Replace libstd, libcore, liballoc in line comments.jonathanCogan-2/+2
2022-12-27Update the documentation of `Vec` to use `extend(array)` instead of ↵Chayim Refael Friedman-1/+1
`extend(array.iter().copied())`
2022-11-28improve docFabian Hintringer-1/+10
2022-11-24Tune RepeatWith::try_fold and Take::for_each and Vec::extend_trustedScott McMurray-5/+4
2022-11-24Stop peeling the last iteration of the loop in `Vec::repeat_with`Scott McMurray-11/+1
2022-11-24Extract the logic for `TrustedLen` to a named method that can be called directlyScott McMurray-0/+35
2022-11-06Vec: IntoIterator signature consistencyripytide-3/+3
Also makes the code dryer.
2022-11-03Fixed typosDouwe Schulte-2/+2
Fixed a typo that has been found on two locations in comments.
2022-10-24Clairify Vec::capacity docsNixon Enraght-Moony-2/+3
Fixes #103326
2022-10-22Rollup merge of #103359 - WaffleLapkin:drain_no_mut_qqq, r=scottmcmMatthias Krüger-3/+1
Remove incorrect comment in `Vec::drain` r? ``@scottmcm`` Turns out this comment wasn't correct for 6 years, since #34951, which switched from using `slice::IterMut` into using `slice::Iter`.
2022-10-21Remove incorrect comment in `Vec::drain`Maybe Waffle-3/+1