Skip to content

Commit 59c38c0

Browse files
committed
Auto merge of rust-lang#123884 - jhpratt:rollup-1kwk0jz, r=jhpratt
Rollup of 4 pull requests Successful merges: - rust-lang#123835 (Avoid more NonNull-raw-NonNull roundtrips in Vec) - rust-lang#123868 (Stabilize (const_)slice_ptr_len and (const_)slice_ptr_is_empty_nonnull) - rust-lang#123872 (Fix Pietro's entry in the mailmap) - rust-lang#123873 (Merge cuviper in the mailmap) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6cfd809 + 1a75ce0 commit 59c38c0

17 files changed

+77
-41
lines changed

.mailmap

+4-1
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ Joseph T. Lyons <[email protected]> <[email protected]>
307307
Josh Cotton <[email protected]>
308308
Josh Driver <[email protected]>
309309
Josh Holmer <[email protected]>
310+
311+
310312
Julian Knodt <[email protected]>
311313
312314
Junyoung Cho <[email protected]>
@@ -474,7 +476,8 @@ Philipp Matthias Schäfer <[email protected]>
474476
phosphorus <[email protected]>
475477
Pierre Krieger <[email protected]>
476478
477-
479+
480+
478481
Pradyumna Rahul <[email protected]>
479482
Przemysław Wesołek <[email protected]> Przemek Wesołek <[email protected]>
480483

library/alloc/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@
151151
#![feature(slice_from_ptr_range)]
152152
#![feature(slice_index_methods)]
153153
#![feature(slice_ptr_get)]
154-
#![feature(slice_ptr_len)]
155154
#![feature(slice_range)]
156155
#![feature(std_internals)]
157156
#![feature(str_internals)]

library/alloc/src/raw_vec.rs

+11
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,17 @@ impl<T, A: Allocator> RawVec<T, A> {
259259
Self { ptr: unsafe { Unique::new_unchecked(ptr) }, cap, alloc }
260260
}
261261

262+
/// A convenience method for hoisting the non-null precondition out of [`RawVec::from_raw_parts_in`].
263+
///
264+
/// # Safety
265+
///
266+
/// See [`RawVec::from_raw_parts_in`].
267+
#[inline]
268+
pub(crate) unsafe fn from_nonnull_in(ptr: NonNull<T>, capacity: usize, alloc: A) -> Self {
269+
let cap = if T::IS_ZST { Cap::ZERO } else { unsafe { Cap(capacity) } };
270+
Self { ptr: Unique::from(ptr), cap, alloc }
271+
}
272+
262273
/// Gets a raw pointer to the start of the allocation. Note that this is
263274
/// `Unique::dangling()` if `capacity == 0` or `T` is zero-sized. In the former case, you must
264275
/// be careful.

library/alloc/src/vec/in_place_collect.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ use core::iter::{InPlaceIterable, SourceIter, TrustedRandomAccessNoCoerce};
161161
use core::marker::PhantomData;
162162
use core::mem::{self, ManuallyDrop, SizedTypeProperties};
163163
use core::num::NonZero;
164-
use core::ptr::{self, NonNull};
164+
use core::ptr;
165165

166166
use super::{InPlaceDrop, InPlaceDstDataSrcBufDrop, SpecFromIter, SpecFromIterNested, Vec};
167167

@@ -254,28 +254,30 @@ where
254254
let (src_buf, src_ptr, src_cap, mut dst_buf, dst_end, dst_cap) = unsafe {
255255
let inner = iterator.as_inner().as_into_iter();
256256
(
257-
inner.buf.as_ptr(),
257+
inner.buf,
258258
inner.ptr,
259259
inner.cap,
260-
inner.buf.as_ptr() as *mut T,
260+
inner.buf.cast::<T>(),
261261
inner.end as *const T,
262262
inner.cap * mem::size_of::<I::Src>() / mem::size_of::<T>(),
263263
)
264264
};
265265

266266
// SAFETY: `dst_buf` and `dst_end` are the start and end of the buffer.
267-
let len = unsafe { SpecInPlaceCollect::collect_in_place(&mut iterator, dst_buf, dst_end) };
267+
let len = unsafe {
268+
SpecInPlaceCollect::collect_in_place(&mut iterator, dst_buf.as_ptr() as *mut T, dst_end)
269+
};
268270

269271
let src = unsafe { iterator.as_inner().as_into_iter() };
270272
// check if SourceIter contract was upheld
271273
// caveat: if they weren't we might not even make it to this point
272-
debug_assert_eq!(src_buf, src.buf.as_ptr());
274+
debug_assert_eq!(src_buf, src.buf);
273275
// check InPlaceIterable contract. This is only possible if the iterator advanced the
274276
// source pointer at all. If it uses unchecked access via TrustedRandomAccess
275277
// then the source pointer will stay in its initial position and we can't use it as reference
276278
if src.ptr != src_ptr {
277279
debug_assert!(
278-
unsafe { dst_buf.add(len) as *const _ } <= src.ptr.as_ptr(),
280+
unsafe { dst_buf.add(len).cast() } <= src.ptr,
279281
"InPlaceIterable contract violation, write pointer advanced beyond read pointer"
280282
);
281283
}
@@ -315,18 +317,17 @@ where
315317
let dst_size = mem::size_of::<T>().unchecked_mul(dst_cap);
316318
let new_layout = Layout::from_size_align_unchecked(dst_size, dst_align);
317319

318-
let result =
319-
alloc.shrink(NonNull::new_unchecked(dst_buf as *mut u8), old_layout, new_layout);
320+
let result = alloc.shrink(dst_buf.cast(), old_layout, new_layout);
320321
let Ok(reallocated) = result else { handle_alloc_error(new_layout) };
321-
dst_buf = reallocated.as_ptr() as *mut T;
322+
dst_buf = reallocated.cast::<T>();
322323
}
323324
} else {
324325
debug_assert_eq!(src_cap * mem::size_of::<I::Src>(), dst_cap * mem::size_of::<T>());
325326
}
326327

327328
mem::forget(dst_guard);
328329

329-
let vec = unsafe { Vec::from_raw_parts(dst_buf, len, dst_cap) };
330+
let vec = unsafe { Vec::from_nonnull(dst_buf, len, dst_cap) };
330331

331332
vec
332333
}

library/alloc/src/vec/in_place_drop.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use core::marker::PhantomData;
2+
use core::ptr::NonNull;
23
use core::ptr::{self, drop_in_place};
34
use core::slice::{self};
45

@@ -31,7 +32,7 @@ impl<T> Drop for InPlaceDrop<T> {
3132
// the source allocation - i.e. before the reallocation happened - to avoid leaking them
3233
// if some other destructor panics.
3334
pub(super) struct InPlaceDstDataSrcBufDrop<Src, Dest> {
34-
pub(super) ptr: *mut Dest,
35+
pub(super) ptr: NonNull<Dest>,
3536
pub(super) len: usize,
3637
pub(super) src_cap: usize,
3738
pub(super) src: PhantomData<Src>,
@@ -42,8 +43,8 @@ impl<Src, Dest> Drop for InPlaceDstDataSrcBufDrop<Src, Dest> {
4243
fn drop(&mut self) {
4344
unsafe {
4445
let _drop_allocation =
45-
RawVec::<Src>::from_raw_parts_in(self.ptr.cast::<Src>(), self.src_cap, Global);
46-
drop_in_place(core::ptr::slice_from_raw_parts_mut::<Dest>(self.ptr, self.len));
46+
RawVec::<Src>::from_nonnull_in(self.ptr.cast::<Src>(), self.src_cap, Global);
47+
drop_in_place(core::ptr::slice_from_raw_parts_mut::<Dest>(self.ptr.as_ptr(), self.len));
4748
};
4849
}
4950
}

library/alloc/src/vec/into_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for IntoIter<T, A> {
433433
// `IntoIter::alloc` is not used anymore after this and will be dropped by RawVec
434434
let alloc = ManuallyDrop::take(&mut self.0.alloc);
435435
// RawVec handles deallocation
436-
let _ = RawVec::from_raw_parts_in(self.0.buf.as_ptr(), self.0.cap, alloc);
436+
let _ = RawVec::from_nonnull_in(self.0.buf, self.0.cap, alloc);
437437
}
438438
}
439439
}

library/alloc/src/vec/mod.rs

+27
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,17 @@ impl<T> Vec<T> {
603603
pub unsafe fn from_raw_parts(ptr: *mut T, length: usize, capacity: usize) -> Self {
604604
unsafe { Self::from_raw_parts_in(ptr, length, capacity, Global) }
605605
}
606+
607+
/// A convenience method for hoisting the non-null precondition out of [`Vec::from_raw_parts`].
608+
///
609+
/// # Safety
610+
///
611+
/// See [`Vec::from_raw_parts`].
612+
#[inline]
613+
#[cfg(not(no_global_oom_handling))] // required by tests/run-make/alloc-no-oom-handling
614+
pub(crate) unsafe fn from_nonnull(ptr: NonNull<T>, length: usize, capacity: usize) -> Self {
615+
unsafe { Self::from_nonnull_in(ptr, length, capacity, Global) }
616+
}
606617
}
607618

608619
impl<T, A: Allocator> Vec<T, A> {
@@ -820,6 +831,22 @@ impl<T, A: Allocator> Vec<T, A> {
820831
unsafe { Vec { buf: RawVec::from_raw_parts_in(ptr, capacity, alloc), len: length } }
821832
}
822833

834+
/// A convenience method for hoisting the non-null precondition out of [`Vec::from_raw_parts_in`].
835+
///
836+
/// # Safety
837+
///
838+
/// See [`Vec::from_raw_parts_in`].
839+
#[inline]
840+
#[cfg(not(no_global_oom_handling))] // required by tests/run-make/alloc-no-oom-handling
841+
pub(crate) unsafe fn from_nonnull_in(
842+
ptr: NonNull<T>,
843+
length: usize,
844+
capacity: usize,
845+
alloc: A,
846+
) -> Self {
847+
unsafe { Vec { buf: RawVec::from_nonnull_in(ptr, capacity, alloc), len: length } }
848+
}
849+
823850
/// Decomposes a `Vec<T>` into its raw components: `(pointer, length, capacity)`.
824851
///
825852
/// Returns the raw pointer to the underlying data, the length of

library/alloc/src/vec/spec_from_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<T> SpecFromIter<T, IntoIter<T>> for Vec<T> {
5151
if has_advanced {
5252
ptr::copy(it.ptr.as_ptr(), it.buf.as_ptr(), it.len());
5353
}
54-
return Vec::from_raw_parts(it.buf.as_ptr(), it.len(), it.cap);
54+
return Vec::from_nonnull(it.buf, it.len(), it.cap);
5555
}
5656
}
5757

library/core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@
159159
#![feature(const_slice_from_raw_parts_mut)]
160160
#![feature(const_slice_from_ref)]
161161
#![feature(const_slice_index)]
162-
#![feature(const_slice_ptr_len)]
163162
#![feature(const_slice_split_at_mut)]
164163
#![feature(const_str_from_utf8_unchecked_mut)]
165164
#![feature(const_strict_overflow_ops)]

library/core/src/ptr/const_ptr.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1647,16 +1647,15 @@ impl<T> *const [T] {
16471647
/// # Examples
16481648
///
16491649
/// ```rust
1650-
/// #![feature(slice_ptr_len)]
1651-
///
16521650
/// use std::ptr;
16531651
///
16541652
/// let slice: *const [i8] = ptr::slice_from_raw_parts(ptr::null(), 3);
16551653
/// assert_eq!(slice.len(), 3);
16561654
/// ```
16571655
#[inline]
1658-
#[unstable(feature = "slice_ptr_len", issue = "71146")]
1659-
#[rustc_const_unstable(feature = "const_slice_ptr_len", issue = "71146")]
1656+
#[stable(feature = "slice_ptr_len", since = "CURRENT_RUSTC_VERSION")]
1657+
#[rustc_const_stable(feature = "const_slice_ptr_len", since = "CURRENT_RUSTC_VERSION")]
1658+
#[rustc_allow_const_fn_unstable(ptr_metadata)]
16601659
pub const fn len(self) -> usize {
16611660
metadata(self)
16621661
}
@@ -1666,15 +1665,14 @@ impl<T> *const [T] {
16661665
/// # Examples
16671666
///
16681667
/// ```
1669-
/// #![feature(slice_ptr_len)]
16701668
/// use std::ptr;
16711669
///
16721670
/// let slice: *const [i8] = ptr::slice_from_raw_parts(ptr::null(), 3);
16731671
/// assert!(!slice.is_empty());
16741672
/// ```
16751673
#[inline(always)]
1676-
#[unstable(feature = "slice_ptr_len", issue = "71146")]
1677-
#[rustc_const_unstable(feature = "const_slice_ptr_len", issue = "71146")]
1674+
#[stable(feature = "slice_ptr_len", since = "CURRENT_RUSTC_VERSION")]
1675+
#[rustc_const_stable(feature = "const_slice_ptr_len", since = "CURRENT_RUSTC_VERSION")]
16781676
pub const fn is_empty(self) -> bool {
16791677
self.len() == 0
16801678
}
@@ -1804,7 +1802,7 @@ impl<T, const N: usize> *const [T; N] {
18041802
/// # Examples
18051803
///
18061804
/// ```
1807-
/// #![feature(array_ptr_get, slice_ptr_len)]
1805+
/// #![feature(array_ptr_get)]
18081806
///
18091807
/// let arr: *const [i32; 3] = &[1, 2, 4] as *const [i32; 3];
18101808
/// let slice: *const [i32] = arr.as_slice();

library/core/src/ptr/mut_ptr.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1909,15 +1909,15 @@ impl<T> *mut [T] {
19091909
/// # Examples
19101910
///
19111911
/// ```rust
1912-
/// #![feature(slice_ptr_len)]
19131912
/// use std::ptr;
19141913
///
19151914
/// let slice: *mut [i8] = ptr::slice_from_raw_parts_mut(ptr::null_mut(), 3);
19161915
/// assert_eq!(slice.len(), 3);
19171916
/// ```
19181917
#[inline(always)]
1919-
#[unstable(feature = "slice_ptr_len", issue = "71146")]
1920-
#[rustc_const_unstable(feature = "const_slice_ptr_len", issue = "71146")]
1918+
#[stable(feature = "slice_ptr_len", since = "CURRENT_RUSTC_VERSION")]
1919+
#[rustc_const_stable(feature = "const_slice_ptr_len", since = "CURRENT_RUSTC_VERSION")]
1920+
#[rustc_allow_const_fn_unstable(ptr_metadata)]
19211921
pub const fn len(self) -> usize {
19221922
metadata(self)
19231923
}
@@ -1927,15 +1927,14 @@ impl<T> *mut [T] {
19271927
/// # Examples
19281928
///
19291929
/// ```
1930-
/// #![feature(slice_ptr_len)]
19311930
/// use std::ptr;
19321931
///
19331932
/// let slice: *mut [i8] = ptr::slice_from_raw_parts_mut(ptr::null_mut(), 3);
19341933
/// assert!(!slice.is_empty());
19351934
/// ```
19361935
#[inline(always)]
1937-
#[unstable(feature = "slice_ptr_len", issue = "71146")]
1938-
#[rustc_const_unstable(feature = "const_slice_ptr_len", issue = "71146")]
1936+
#[stable(feature = "slice_ptr_len", since = "CURRENT_RUSTC_VERSION")]
1937+
#[rustc_const_stable(feature = "const_slice_ptr_len", since = "CURRENT_RUSTC_VERSION")]
19391938
pub const fn is_empty(self) -> bool {
19401939
self.len() == 0
19411940
}

library/core/src/ptr/non_null.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,6 @@ impl<T> NonNull<[T]> {
15621562
/// ```
15631563
#[stable(feature = "slice_ptr_len_nonnull", since = "1.63.0")]
15641564
#[rustc_const_stable(feature = "const_slice_ptr_len_nonnull", since = "1.63.0")]
1565-
#[rustc_allow_const_fn_unstable(const_slice_ptr_len)]
15661565
#[must_use]
15671566
#[inline]
15681567
pub const fn len(self) -> usize {
@@ -1574,14 +1573,16 @@ impl<T> NonNull<[T]> {
15741573
/// # Examples
15751574
///
15761575
/// ```rust
1577-
/// #![feature(slice_ptr_is_empty_nonnull)]
15781576
/// use std::ptr::NonNull;
15791577
///
15801578
/// let slice: NonNull<[i8]> = NonNull::slice_from_raw_parts(NonNull::dangling(), 3);
15811579
/// assert!(!slice.is_empty());
15821580
/// ```
1583-
#[unstable(feature = "slice_ptr_is_empty_nonnull", issue = "71146")]
1584-
#[rustc_const_unstable(feature = "const_slice_ptr_is_empty_nonnull", issue = "71146")]
1581+
#[stable(feature = "slice_ptr_is_empty_nonnull", since = "CURRENT_RUSTC_VERSION")]
1582+
#[rustc_const_stable(
1583+
feature = "const_slice_ptr_is_empty_nonnull",
1584+
since = "CURRENT_RUSTC_VERSION"
1585+
)]
15851586
#[must_use]
15861587
#[inline]
15871588
pub const fn is_empty(self) -> bool {

library/core/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
#![feature(sort_internals)]
5555
#![feature(slice_take)]
5656
#![feature(slice_from_ptr_range)]
57-
#![feature(slice_ptr_len)]
5857
#![feature(slice_split_once)]
5958
#![feature(split_as_slice)]
6059
#![feature(maybe_uninit_fill)]

library/std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@
265265
feature(slice_index_methods, coerce_unsized, sgx_platform)
266266
)]
267267
#![cfg_attr(any(windows, target_os = "uefi"), feature(round_char_boundary))]
268-
#![cfg_attr(target_os = "xous", feature(slice_ptr_len))]
269268
#![cfg_attr(target_family = "wasm", feature(stdarch_wasm_atomic_wait))]
270269
#![cfg_attr(
271270
all(any(target_arch = "x86_64", target_arch = "x86"), target_os = "uefi"),

tests/ui/consts/const_fn_unsize.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ run-pass
2-
#![feature(slice_ptr_len)]
32

43
use std::ptr::NonNull;
54

tests/ui/suggestions/deref-path-method.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ note: if you're trying to build a new `Vec<_, _>` consider using one of the foll
99
Vec::<T>::with_capacity
1010
Vec::<T>::try_with_capacity
1111
Vec::<T>::from_raw_parts
12-
and 4 others
12+
and 6 others
1313
--> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
1414
help: the function `contains` is implemented on `[_]`
1515
|

tests/ui/ufcs/bad-builder.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ note: if you're trying to build a new `Vec<Q>` consider using one of the followi
99
Vec::<T>::with_capacity
1010
Vec::<T>::try_with_capacity
1111
Vec::<T>::from_raw_parts
12-
and 4 others
12+
and 6 others
1313
--> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
1414
help: there is an associated function `new` with a similar name
1515
|

0 commit comments

Comments
 (0)