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
d19b64fb54/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.
This commit is contained in:
commit
581e7417ce
4 changed files with 7 additions and 15 deletions
|
@ -7,7 +7,7 @@ use core::fmt::{self, Debug, Display, Formatter};
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
#[cfg(not(no_global_oom_handling))]
|
#[cfg(not(no_global_oom_handling))]
|
||||||
use core::marker::Unsize;
|
use core::marker::Unsize;
|
||||||
use core::mem;
|
use core::mem::{self, SizedTypeProperties};
|
||||||
use core::ops::{Deref, DerefMut};
|
use core::ops::{Deref, DerefMut};
|
||||||
use core::ptr::Pointee;
|
use core::ptr::Pointee;
|
||||||
use core::ptr::{self, NonNull};
|
use core::ptr::{self, NonNull};
|
||||||
|
@ -202,9 +202,7 @@ impl<H> WithHeader<H> {
|
||||||
let ptr = if layout.size() == 0 {
|
let ptr = if layout.size() == 0 {
|
||||||
// Some paranoia checking, mostly so that the ThinBox tests are
|
// Some paranoia checking, mostly so that the ThinBox tests are
|
||||||
// more able to catch issues.
|
// more able to catch issues.
|
||||||
debug_assert!(
|
debug_assert!(value_offset == 0 && T::IS_ZST && H::IS_ZST);
|
||||||
value_offset == 0 && mem::size_of::<T>() == 0 && mem::size_of::<H>() == 0
|
|
||||||
);
|
|
||||||
layout.dangling()
|
layout.dangling()
|
||||||
} else {
|
} else {
|
||||||
let ptr = alloc::alloc(layout);
|
let ptr = alloc::alloc(layout);
|
||||||
|
@ -249,9 +247,7 @@ impl<H> WithHeader<H> {
|
||||||
alloc::dealloc(self.ptr.as_ptr().sub(value_offset), layout);
|
alloc::dealloc(self.ptr.as_ptr().sub(value_offset), layout);
|
||||||
} else {
|
} else {
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
value_offset == 0
|
value_offset == 0 && H::IS_ZST && self.value_layout.size() == 0
|
||||||
&& mem::size_of::<H>() == 0
|
|
||||||
&& self.value_layout.size() == 0
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,9 +112,7 @@ impl<'a, T, A: Allocator> Drain<'a, T, A> {
|
||||||
let unyielded_ptr = this.iter.as_slice().as_ptr();
|
let unyielded_ptr = this.iter.as_slice().as_ptr();
|
||||||
|
|
||||||
// ZSTs have no identity, so we don't need to move them around.
|
// ZSTs have no identity, so we don't need to move them around.
|
||||||
let needs_move = mem::size_of::<T>() != 0;
|
if !T::IS_ZST {
|
||||||
|
|
||||||
if needs_move {
|
|
||||||
let start_ptr = source_vec.as_mut_ptr().add(start);
|
let start_ptr = source_vec.as_mut_ptr().add(start);
|
||||||
|
|
||||||
// memmove back unyielded elements
|
// memmove back unyielded elements
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::alloc::{Allocator, Global};
|
use crate::alloc::{Allocator, Global};
|
||||||
use core::mem::{self, ManuallyDrop};
|
use core::mem::{ManuallyDrop, SizedTypeProperties};
|
||||||
use core::ptr;
|
use core::ptr;
|
||||||
use core::slice;
|
use core::slice;
|
||||||
|
|
||||||
|
@ -96,9 +96,7 @@ where
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
// ZSTs have no identity, so we don't need to move them around.
|
// ZSTs have no identity, so we don't need to move them around.
|
||||||
let needs_move = mem::size_of::<T>() != 0;
|
if !T::IS_ZST && this.idx < this.old_len && this.del > 0 {
|
||||||
|
|
||||||
if needs_move && this.idx < this.old_len && this.del > 0 {
|
|
||||||
let ptr = this.vec.as_mut_ptr();
|
let ptr = this.vec.as_mut_ptr();
|
||||||
let src = ptr.add(this.idx);
|
let src = ptr.add(this.idx);
|
||||||
let dst = src.sub(this.del);
|
let dst = src.sub(this.del);
|
||||||
|
|
|
@ -73,7 +73,7 @@ macro_rules! iterator {
|
||||||
// Unsafe because the offset must not exceed `self.len()`.
|
// Unsafe because the offset must not exceed `self.len()`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
unsafe fn post_inc_start(&mut self, offset: usize) -> * $raw_mut T {
|
unsafe fn post_inc_start(&mut self, offset: usize) -> * $raw_mut T {
|
||||||
if mem::size_of::<T>() == 0 {
|
if T::IS_ZST {
|
||||||
zst_shrink!(self, offset);
|
zst_shrink!(self, offset);
|
||||||
self.ptr.as_ptr()
|
self.ptr.as_ptr()
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue