diff options
| author | Ben Kimock <kimockb@gmail.com> | 2024-02-07 10:29:33 -0500 |
|---|---|---|
| committer | Ben Kimock <kimockb@gmail.com> | 2024-02-08 11:52:16 -0500 |
| commit | 88d6e9f868d7bd21aa2b6c641f8743fe7e53e67b (patch) | |
| tree | 493b44278bd94ad3247b34aaddbd559911bea4bf /library/alloc/src/vec | |
| parent | b0ea682a2cad2c49595c95dcb7e7608d090484f1 (diff) | |
| download | rust-88d6e9f868d7bd21aa2b6c641f8743fe7e53e67b.tar.gz rust-88d6e9f868d7bd21aa2b6c641f8743fe7e53e67b.zip | |
Reduce use of NonNull::new_unchecked in library/
Diffstat (limited to 'library/alloc/src/vec')
| -rw-r--r-- | library/alloc/src/vec/into_iter.rs | 2 | ||||
| -rw-r--r-- | library/alloc/src/vec/mod.rs | 6 |
2 files changed, 4 insertions, 4 deletions
diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 654ce09afcd..7800560da94 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -136,7 +136,7 @@ impl<T, A: Allocator> IntoIter<T, A> { // struct and then overwriting &mut self. // this creates less assembly self.cap = 0; - self.buf = unsafe { NonNull::new_unchecked(RawVec::NEW.ptr()) }; + self.buf = RawVec::NEW.non_null(); self.ptr = self.buf; self.end = self.buf.as_ptr(); diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index b3e5ecc9240..08e3cdedc66 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2861,16 +2861,16 @@ impl<T, A: Allocator> IntoIterator for Vec<T, A> { #[inline] fn into_iter(self) -> Self::IntoIter { unsafe { - let mut me = ManuallyDrop::new(self); + let me = ManuallyDrop::new(self); let alloc = ManuallyDrop::new(ptr::read(me.allocator())); - let begin = me.as_mut_ptr(); + let buf = me.buf.non_null(); + let begin = buf.as_ptr(); let end = if T::IS_ZST { begin.wrapping_byte_add(me.len()) } else { begin.add(me.len()) as *const T }; let cap = me.buf.capacity(); - let buf = NonNull::new_unchecked(begin); IntoIter { buf, phantom: PhantomData, cap, alloc, ptr: buf, end } } } |
