about summary refs log tree commit diff
path: root/library/alloc/src/vec/drain.rs
AgeCommit message (Collapse)AuthorLines
2025-02-23rename sub_ptr 😅bendn-1/+1
2024-07-29Reformat `use` declarations.Nicholas Nethercote-1/+1
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2023-05-07enable `rust_2018_idioms` for doctestsozkanonur-1/+1
Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-04-22Rollup merge of #110635 - scottmcm:zst-checks, r=the8472Yuki Okushi-3/+1
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-3/+1
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-01-17Don't do pointer arithmetic on pointers to deallocated memoryThe 8472-3/+3
vec::Splice can invalidate the slice::Iter inside vec::Drain. So we replace them with dangling pointers which, unlike ones to deallocated memory, are allowed.
2022-09-22Make ZST checks in core/alloc more readableScott McMurray-2/+2
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-08-28fill-in tracking issue for `feature(drain_keep_rest)`Maybe Waffle-1/+1
2022-08-28add examples to `vec::Drain{,Filter}::keep_rest` docsMaybe Waffle-0/+18
2022-06-05Add vec::Drain{,Filter}::keep_restMaybe Waffle-1/+54
These methods allow to cancel draining of unyielded elements.
2022-05-11Rename `unsigned_offset_from` to `sub_ptr`Scott McMurray-1/+1
2022-05-11Add `unsigned_offset_from` on pointersScott McMurray-1/+1
Like we have `add`/`sub` which are the `usize` version of `offset`, this adds the `usize` equivalent of `offset_from`. Like how `.add(d)` replaced a whole bunch of `.offset(d as isize)`, you can see from the changes here that it's fairly common that code actually knows the order between the pointers and *wants* a `usize`, not an `isize`. As a bonus, this can do `sub nuw`+`udiv exact`, rather than `sub`+`sdiv exact`, which can be optimized slightly better because it doesn't have to worry about negatives. That's why the slice iterators weren't using `offset_from`, though I haven't updated that code in this PR because slices are so perf-critical that I'll do it as its own change. This is an intrinsic, like `offset_from`, so that it can eventually be allowed in CTFE. It also allows checking the extra safety condition -- see the test confirming that CTFE catches it if you pass the pointers in the wrong order.
2021-12-11Fix zero-sized reference to deallocated memoryThe 8472-4/+6
fixes #91772
2021-12-09Use `*mut [T]` instead of `[MaybeUninit<T>]`The 8472-7/+5
2021-11-20document why we're not directly passing drop_ptr to drop_in_placeThe8472-0/+4
2021-11-20replace vec::Drain drop loops with drop_in_placeThe8472-14/+37
2021-10-15Add #[must_use] to remaining alloc functionsJohn Kugelman-0/+1
2021-10-11Add #[must_use] to as_type conversionsJohn Kugelman-0/+1
2020-12-29style: applying Rust styleC-5/+3
2020-12-29refactor: moving Drain into drain.rsC-0/+157