diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2023-04-22 10:33:57 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-22 10:33:57 +0900 |
| commit | 581e7417ce4e9e1d4adb775bb00d7cc4ea905eee (patch) | |
| tree | 70d87f7c6276366b2320cc4f7df9d95ff810d2e0 /library/alloc/src/vec | |
| parent | 9a798e416cd998aba2b17aeb89a0f707c2e40ae9 (diff) | |
| parent | 56613f8c382351898f9267bac8e8324f118eb79d (diff) | |
| download | rust-581e7417ce4e9e1d4adb775bb00d7cc4ea905eee.tar.gz rust-581e7417ce4e9e1d4adb775bb00d7cc4ea905eee.zip | |
Rollup merge of #110635 - scottmcm:zst-checks, r=the8472
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.
Diffstat (limited to 'library/alloc/src/vec')
| -rw-r--r-- | library/alloc/src/vec/drain.rs | 4 | ||||
| -rw-r--r-- | library/alloc/src/vec/drain_filter.rs | 6 |
2 files changed, 3 insertions, 7 deletions
diff --git a/library/alloc/src/vec/drain.rs b/library/alloc/src/vec/drain.rs index e3ca6eb7833..3091efabd68 100644 --- a/library/alloc/src/vec/drain.rs +++ b/library/alloc/src/vec/drain.rs @@ -112,9 +112,7 @@ impl<'a, T, A: Allocator> Drain<'a, T, A> { let unyielded_ptr = this.iter.as_slice().as_ptr(); // ZSTs have no identity, so we don't need to move them around. - let needs_move = mem::size_of::<T>() != 0; - - if needs_move { + if !T::IS_ZST { let start_ptr = source_vec.as_mut_ptr().add(start); // memmove back unyielded elements diff --git a/library/alloc/src/vec/drain_filter.rs b/library/alloc/src/vec/drain_filter.rs index 8c03f1692d9..650f9213890 100644 --- a/library/alloc/src/vec/drain_filter.rs +++ b/library/alloc/src/vec/drain_filter.rs @@ -1,5 +1,5 @@ use crate::alloc::{Allocator, Global}; -use core::mem::{self, ManuallyDrop}; +use core::mem::{ManuallyDrop, SizedTypeProperties}; use core::ptr; use core::slice; @@ -96,9 +96,7 @@ where unsafe { // ZSTs have no identity, so we don't need to move them around. - let needs_move = mem::size_of::<T>() != 0; - - if needs_move && this.idx < this.old_len && this.del > 0 { + if !T::IS_ZST && this.idx < this.old_len && this.del > 0 { let ptr = this.vec.as_mut_ptr(); let src = ptr.add(this.idx); let dst = src.sub(this.del); |
