Stabilize non_null_convenience
Fully stabilize the following API, including const where applicable: impl <T> NonNull<T> { pub const unsafe fn offset(self, count: isize) -> Self; pub const unsafe fn add(self, count: usize) -> Self; pub const unsafe fn sub(self, count: usize) -> Self; pub const unsafe fn offset_from(self, origin: NonNull<T>) -> isize; pub const unsafe fn read(self) -> T; pub unsafe fn read_volatile(self) -> T; pub const unsafe fn read_unaligned(self) -> T; pub unsafe fn write_volatile(self, val: T); pub unsafe fn replace(self, src: T) -> T; } impl<T: ?Sized> NonNull<T> { pub const unsafe fn byte_offset(self, count: isize) -> Self; pub const unsafe fn byte_add(self, count: usize) -> Self; pub const unsafe fn byte_sub(self, count: usize) -> Self; pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: NonNull<U>) -> isize; pub unsafe fn drop_in_place(self); } Stabilize the following without const: impl <T> NonNull<T> { // const under `const_intrinsic_copy` pub const unsafe fn copy_to(self, dest: NonNull<T>, count: usize); pub const unsafe fn copy_to_nonoverlapping(self, dest: NonNull<T>, count: usize); pub const unsafe fn copy_from(self, src: NonNull<T>, count: usize); pub const unsafe fn copy_from_nonoverlapping(self, src: NonNull<T>, count: usize); // const under `const_ptr_write` pub const unsafe fn write(self, val: T); pub const unsafe fn write_bytes(self, val: u8, count: usize); pub const unsafe fn write_unaligned(self, val: T); // const under `const_swap` pub const unsafe fn swap(self, with: NonNull<T>); // const under `const_align_offset` pub const fn align_offset(self, align: usize) -> usize; // const under `const_pointer_is_aligned` pub const fn is_aligned(self) -> bool; } Left the following unstable: impl <T> NonNull<T> { // moved gate to `ptr_sub_ptr` pub const unsafe fn sub_ptr(self, subtracted: NonNull<T>) -> usize; } impl <T: ?Sized> NonNull<T> { // moved gate to `pointer_is_aligned_to` pub const fn is_aligned_to(self, align: usize) -> bool; } Fixes: https://github.com/rust-lang/rust/issues/117691
This commit is contained in:
parent
ce609db948
commit
e0f8202ed5
@ -137,7 +137,6 @@
|
|||||||
#![feature(maybe_uninit_slice)]
|
#![feature(maybe_uninit_slice)]
|
||||||
#![feature(maybe_uninit_uninit_array)]
|
#![feature(maybe_uninit_uninit_array)]
|
||||||
#![feature(maybe_uninit_uninit_array_transpose)]
|
#![feature(maybe_uninit_uninit_array_transpose)]
|
||||||
#![feature(non_null_convenience)]
|
|
||||||
#![feature(panic_internals)]
|
#![feature(panic_internals)]
|
||||||
#![feature(pattern)]
|
#![feature(pattern)]
|
||||||
#![feature(ptr_internals)]
|
#![feature(ptr_internals)]
|
||||||
|
@ -180,7 +180,6 @@
|
|||||||
#![feature(isqrt)]
|
#![feature(isqrt)]
|
||||||
#![feature(link_cfg)]
|
#![feature(link_cfg)]
|
||||||
#![feature(maybe_uninit_uninit_array)]
|
#![feature(maybe_uninit_uninit_array)]
|
||||||
#![feature(non_null_convenience)]
|
|
||||||
#![feature(offset_of_enum)]
|
#![feature(offset_of_enum)]
|
||||||
#![feature(offset_of_nested)]
|
#![feature(offset_of_nested)]
|
||||||
#![feature(panic_internals)]
|
#![feature(panic_internals)]
|
||||||
|
@ -512,7 +512,6 @@ pub const fn cast<U>(self) -> NonNull<U> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(non_null_convenience)]
|
|
||||||
/// use std::ptr::NonNull;
|
/// use std::ptr::NonNull;
|
||||||
///
|
///
|
||||||
/// let mut s = [1, 2, 3];
|
/// let mut s = [1, 2, 3];
|
||||||
@ -523,12 +522,12 @@ pub const fn cast<U>(self) -> NonNull<U> {
|
|||||||
/// println!("{}", ptr.offset(2).read());
|
/// println!("{}", ptr.offset(2).read());
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[must_use = "returns a new pointer rather than modifying its argument"]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
pub const unsafe fn offset(self, count: isize) -> NonNull<T>
|
#[must_use = "returns a new pointer rather than modifying its argument"]
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
pub const unsafe fn offset(self, count: isize) -> Self
|
||||||
where
|
where
|
||||||
T: Sized,
|
T: Sized,
|
||||||
{
|
{
|
||||||
@ -549,11 +548,11 @@ pub const fn cast<U>(self) -> NonNull<U> {
|
|||||||
///
|
///
|
||||||
/// For non-`Sized` pointees this operation changes only the data pointer,
|
/// For non-`Sized` pointees this operation changes only the data pointer,
|
||||||
/// leaving the metadata untouched.
|
/// leaving the metadata untouched.
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub const unsafe fn byte_offset(self, count: isize) -> Self {
|
pub const unsafe fn byte_offset(self, count: isize) -> Self {
|
||||||
// SAFETY: the caller must uphold the safety contract for `offset` and `byte_offset` has
|
// SAFETY: the caller must uphold the safety contract for `offset` and `byte_offset` has
|
||||||
// the same safety contract.
|
// the same safety contract.
|
||||||
@ -599,7 +598,6 @@ pub const fn cast<U>(self) -> NonNull<U> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(non_null_convenience)]
|
|
||||||
/// use std::ptr::NonNull;
|
/// use std::ptr::NonNull;
|
||||||
///
|
///
|
||||||
/// let s: &str = "123";
|
/// let s: &str = "123";
|
||||||
@ -610,11 +608,11 @@ pub const fn cast<U>(self) -> NonNull<U> {
|
|||||||
/// println!("{}", ptr.add(2).read() as char);
|
/// println!("{}", ptr.add(2).read() as char);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[must_use = "returns a new pointer rather than modifying its argument"]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
|
#[must_use = "returns a new pointer rather than modifying its argument"]
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub const unsafe fn add(self, count: usize) -> Self
|
pub const unsafe fn add(self, count: usize) -> Self
|
||||||
where
|
where
|
||||||
T: Sized,
|
T: Sized,
|
||||||
@ -636,12 +634,12 @@ pub const fn cast<U>(self) -> NonNull<U> {
|
|||||||
///
|
///
|
||||||
/// For non-`Sized` pointees this operation changes only the data pointer,
|
/// For non-`Sized` pointees this operation changes only the data pointer,
|
||||||
/// leaving the metadata untouched.
|
/// leaving the metadata untouched.
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[rustc_allow_const_fn_unstable(set_ptr_value)]
|
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
|
#[rustc_allow_const_fn_unstable(set_ptr_value)]
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub const unsafe fn byte_add(self, count: usize) -> Self {
|
pub const unsafe fn byte_add(self, count: usize) -> Self {
|
||||||
// SAFETY: the caller must uphold the safety contract for `add` and `byte_add` has the same
|
// SAFETY: the caller must uphold the safety contract for `add` and `byte_add` has the same
|
||||||
// safety contract.
|
// safety contract.
|
||||||
@ -688,7 +686,6 @@ pub const fn cast<U>(self) -> NonNull<U> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(non_null_convenience)]
|
|
||||||
/// use std::ptr::NonNull;
|
/// use std::ptr::NonNull;
|
||||||
///
|
///
|
||||||
/// let s: &str = "123";
|
/// let s: &str = "123";
|
||||||
@ -699,11 +696,11 @@ pub const fn cast<U>(self) -> NonNull<U> {
|
|||||||
/// println!("{}", end.sub(2).read() as char);
|
/// println!("{}", end.sub(2).read() as char);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[must_use = "returns a new pointer rather than modifying its argument"]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
|
#[must_use = "returns a new pointer rather than modifying its argument"]
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub const unsafe fn sub(self, count: usize) -> Self
|
pub const unsafe fn sub(self, count: usize) -> Self
|
||||||
where
|
where
|
||||||
T: Sized,
|
T: Sized,
|
||||||
@ -730,12 +727,12 @@ pub const fn cast<U>(self) -> NonNull<U> {
|
|||||||
///
|
///
|
||||||
/// For non-`Sized` pointees this operation changes only the data pointer,
|
/// For non-`Sized` pointees this operation changes only the data pointer,
|
||||||
/// leaving the metadata untouched.
|
/// leaving the metadata untouched.
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[rustc_allow_const_fn_unstable(set_ptr_value)]
|
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
|
#[rustc_allow_const_fn_unstable(set_ptr_value)]
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub const unsafe fn byte_sub(self, count: usize) -> Self {
|
pub const unsafe fn byte_sub(self, count: usize) -> Self {
|
||||||
// SAFETY: the caller must uphold the safety contract for `sub` and `byte_sub` has the same
|
// SAFETY: the caller must uphold the safety contract for `sub` and `byte_sub` has the same
|
||||||
// safety contract.
|
// safety contract.
|
||||||
@ -816,7 +813,6 @@ pub const fn cast<U>(self) -> NonNull<U> {
|
|||||||
/// Basic usage:
|
/// Basic usage:
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(non_null_convenience)]
|
|
||||||
/// use std::ptr::NonNull;
|
/// use std::ptr::NonNull;
|
||||||
///
|
///
|
||||||
/// let a = [0; 5];
|
/// let a = [0; 5];
|
||||||
@ -833,7 +829,7 @@ pub const fn cast<U>(self) -> NonNull<U> {
|
|||||||
/// *Incorrect* usage:
|
/// *Incorrect* usage:
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// #![feature(non_null_convenience, strict_provenance)]
|
/// #![feature(strict_provenance)]
|
||||||
/// use std::ptr::NonNull;
|
/// use std::ptr::NonNull;
|
||||||
///
|
///
|
||||||
/// let ptr1 = NonNull::new(Box::into_raw(Box::new(0u8))).unwrap();
|
/// let ptr1 = NonNull::new(Box::into_raw(Box::new(0u8))).unwrap();
|
||||||
@ -845,14 +841,13 @@ pub const fn cast<U>(self) -> NonNull<U> {
|
|||||||
/// // Since ptr2_other and ptr2 are derived from pointers to different objects,
|
/// // Since ptr2_other and ptr2 are derived from pointers to different objects,
|
||||||
/// // computing their offset is undefined behavior, even though
|
/// // computing their offset is undefined behavior, even though
|
||||||
/// // they point to the same address!
|
/// // they point to the same address!
|
||||||
/// unsafe {
|
///
|
||||||
/// let zero = ptr2_other.offset_from(ptr2); // Undefined Behavior
|
/// let zero = unsafe { ptr2_other.offset_from(ptr2) }; // Undefined Behavior
|
||||||
/// }
|
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub const unsafe fn offset_from(self, origin: NonNull<T>) -> isize
|
pub const unsafe fn offset_from(self, origin: NonNull<T>) -> isize
|
||||||
where
|
where
|
||||||
T: Sized,
|
T: Sized,
|
||||||
@ -870,10 +865,10 @@ pub const fn cast<U>(self) -> NonNull<U> {
|
|||||||
///
|
///
|
||||||
/// For non-`Sized` pointees this operation considers only the data pointers,
|
/// For non-`Sized` pointees this operation considers only the data pointers,
|
||||||
/// ignoring the metadata.
|
/// ignoring the metadata.
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: NonNull<U>) -> isize {
|
pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: NonNull<U>) -> isize {
|
||||||
// SAFETY: the caller must uphold the safety contract for `byte_offset_from`.
|
// SAFETY: the caller must uphold the safety contract for `byte_offset_from`.
|
||||||
unsafe { self.pointer.byte_offset_from(origin.pointer) }
|
unsafe { self.pointer.byte_offset_from(origin.pointer) }
|
||||||
@ -897,7 +892,7 @@ pub const fn cast<U>(self) -> NonNull<U> {
|
|||||||
/// to [`sub`](#method.sub)). The following are all equivalent, assuming
|
/// to [`sub`](#method.sub)). The following are all equivalent, assuming
|
||||||
/// that their safety preconditions are met:
|
/// that their safety preconditions are met:
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # #![feature(non_null_convenience)]
|
/// # #![feature(ptr_sub_ptr)]
|
||||||
/// # unsafe fn blah(ptr: std::ptr::NonNull<u32>, origin: std::ptr::NonNull<u32>, count: usize) -> bool {
|
/// # unsafe fn blah(ptr: std::ptr::NonNull<u32>, origin: std::ptr::NonNull<u32>, count: usize) -> bool {
|
||||||
/// ptr.sub_ptr(origin) == count
|
/// ptr.sub_ptr(origin) == count
|
||||||
/// # &&
|
/// # &&
|
||||||
@ -926,7 +921,7 @@ pub const fn cast<U>(self) -> NonNull<U> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(non_null_convenience)]
|
/// #![feature(ptr_sub_ptr)]
|
||||||
/// use std::ptr::NonNull;
|
/// use std::ptr::NonNull;
|
||||||
///
|
///
|
||||||
/// let a = [0; 5];
|
/// let a = [0; 5];
|
||||||
@ -942,12 +937,10 @@ pub const fn cast<U>(self) -> NonNull<U> {
|
|||||||
/// // This would be incorrect, as the pointers are not correctly ordered:
|
/// // This would be incorrect, as the pointers are not correctly ordered:
|
||||||
/// // ptr1.sub_ptr(ptr2)
|
/// // ptr1.sub_ptr(ptr2)
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
// #[unstable(feature = "ptr_sub_ptr", issue = "95892")]
|
|
||||||
// #[rustc_const_unstable(feature = "const_ptr_sub_ptr", issue = "95892")]
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
|
#[unstable(feature = "ptr_sub_ptr", issue = "95892")]
|
||||||
|
#[rustc_const_unstable(feature = "const_ptr_sub_ptr", issue = "95892")]
|
||||||
pub const unsafe fn sub_ptr(self, subtracted: NonNull<T>) -> usize
|
pub const unsafe fn sub_ptr(self, subtracted: NonNull<T>) -> usize
|
||||||
where
|
where
|
||||||
T: Sized,
|
T: Sized,
|
||||||
@ -962,10 +955,10 @@ pub const fn cast<U>(self) -> NonNull<U> {
|
|||||||
/// See [`ptr::read`] for safety concerns and examples.
|
/// See [`ptr::read`] for safety concerns and examples.
|
||||||
///
|
///
|
||||||
/// [`ptr::read`]: crate::ptr::read()
|
/// [`ptr::read`]: crate::ptr::read()
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub const unsafe fn read(self) -> T
|
pub const unsafe fn read(self) -> T
|
||||||
where
|
where
|
||||||
T: Sized,
|
T: Sized,
|
||||||
@ -984,9 +977,9 @@ pub const fn cast<U>(self) -> NonNull<U> {
|
|||||||
/// See [`ptr::read_volatile`] for safety concerns and examples.
|
/// See [`ptr::read_volatile`] for safety concerns and examples.
|
||||||
///
|
///
|
||||||
/// [`ptr::read_volatile`]: crate::ptr::read_volatile()
|
/// [`ptr::read_volatile`]: crate::ptr::read_volatile()
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub unsafe fn read_volatile(self) -> T
|
pub unsafe fn read_volatile(self) -> T
|
||||||
where
|
where
|
||||||
T: Sized,
|
T: Sized,
|
||||||
@ -1003,10 +996,10 @@ pub unsafe fn read_volatile(self) -> T
|
|||||||
/// See [`ptr::read_unaligned`] for safety concerns and examples.
|
/// See [`ptr::read_unaligned`] for safety concerns and examples.
|
||||||
///
|
///
|
||||||
/// [`ptr::read_unaligned`]: crate::ptr::read_unaligned()
|
/// [`ptr::read_unaligned`]: crate::ptr::read_unaligned()
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub const unsafe fn read_unaligned(self) -> T
|
pub const unsafe fn read_unaligned(self) -> T
|
||||||
where
|
where
|
||||||
T: Sized,
|
T: Sized,
|
||||||
@ -1023,10 +1016,10 @@ pub unsafe fn read_volatile(self) -> T
|
|||||||
/// See [`ptr::copy`] for safety concerns and examples.
|
/// See [`ptr::copy`] for safety concerns and examples.
|
||||||
///
|
///
|
||||||
/// [`ptr::copy`]: crate::ptr::copy()
|
/// [`ptr::copy`]: crate::ptr::copy()
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
|
||||||
pub const unsafe fn copy_to(self, dest: NonNull<T>, count: usize)
|
pub const unsafe fn copy_to(self, dest: NonNull<T>, count: usize)
|
||||||
where
|
where
|
||||||
T: Sized,
|
T: Sized,
|
||||||
@ -1043,10 +1036,10 @@ pub unsafe fn read_volatile(self) -> T
|
|||||||
/// See [`ptr::copy_nonoverlapping`] for safety concerns and examples.
|
/// See [`ptr::copy_nonoverlapping`] for safety concerns and examples.
|
||||||
///
|
///
|
||||||
/// [`ptr::copy_nonoverlapping`]: crate::ptr::copy_nonoverlapping()
|
/// [`ptr::copy_nonoverlapping`]: crate::ptr::copy_nonoverlapping()
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
|
||||||
pub const unsafe fn copy_to_nonoverlapping(self, dest: NonNull<T>, count: usize)
|
pub const unsafe fn copy_to_nonoverlapping(self, dest: NonNull<T>, count: usize)
|
||||||
where
|
where
|
||||||
T: Sized,
|
T: Sized,
|
||||||
@ -1063,10 +1056,10 @@ pub unsafe fn read_volatile(self) -> T
|
|||||||
/// See [`ptr::copy`] for safety concerns and examples.
|
/// See [`ptr::copy`] for safety concerns and examples.
|
||||||
///
|
///
|
||||||
/// [`ptr::copy`]: crate::ptr::copy()
|
/// [`ptr::copy`]: crate::ptr::copy()
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
|
||||||
pub const unsafe fn copy_from(self, src: NonNull<T>, count: usize)
|
pub const unsafe fn copy_from(self, src: NonNull<T>, count: usize)
|
||||||
where
|
where
|
||||||
T: Sized,
|
T: Sized,
|
||||||
@ -1083,10 +1076,10 @@ pub unsafe fn read_volatile(self) -> T
|
|||||||
/// See [`ptr::copy_nonoverlapping`] for safety concerns and examples.
|
/// See [`ptr::copy_nonoverlapping`] for safety concerns and examples.
|
||||||
///
|
///
|
||||||
/// [`ptr::copy_nonoverlapping`]: crate::ptr::copy_nonoverlapping()
|
/// [`ptr::copy_nonoverlapping`]: crate::ptr::copy_nonoverlapping()
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
|
||||||
pub const unsafe fn copy_from_nonoverlapping(self, src: NonNull<T>, count: usize)
|
pub const unsafe fn copy_from_nonoverlapping(self, src: NonNull<T>, count: usize)
|
||||||
where
|
where
|
||||||
T: Sized,
|
T: Sized,
|
||||||
@ -1100,8 +1093,8 @@ pub unsafe fn read_volatile(self) -> T
|
|||||||
/// See [`ptr::drop_in_place`] for safety concerns and examples.
|
/// See [`ptr::drop_in_place`] for safety concerns and examples.
|
||||||
///
|
///
|
||||||
/// [`ptr::drop_in_place`]: crate::ptr::drop_in_place()
|
/// [`ptr::drop_in_place`]: crate::ptr::drop_in_place()
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub unsafe fn drop_in_place(self) {
|
pub unsafe fn drop_in_place(self) {
|
||||||
// SAFETY: the caller must uphold the safety contract for `drop_in_place`.
|
// SAFETY: the caller must uphold the safety contract for `drop_in_place`.
|
||||||
unsafe { ptr::drop_in_place(self.as_ptr()) }
|
unsafe { ptr::drop_in_place(self.as_ptr()) }
|
||||||
@ -1113,11 +1106,10 @@ pub unsafe fn drop_in_place(self) {
|
|||||||
/// See [`ptr::write`] for safety concerns and examples.
|
/// See [`ptr::write`] for safety concerns and examples.
|
||||||
///
|
///
|
||||||
/// [`ptr::write`]: crate::ptr::write()
|
/// [`ptr::write`]: crate::ptr::write()
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
//#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
|
||||||
pub const unsafe fn write(self, val: T)
|
pub const unsafe fn write(self, val: T)
|
||||||
where
|
where
|
||||||
T: Sized,
|
T: Sized,
|
||||||
@ -1132,12 +1124,11 @@ pub unsafe fn drop_in_place(self) {
|
|||||||
/// See [`ptr::write_bytes`] for safety concerns and examples.
|
/// See [`ptr::write_bytes`] for safety concerns and examples.
|
||||||
///
|
///
|
||||||
/// [`ptr::write_bytes`]: crate::ptr::write_bytes()
|
/// [`ptr::write_bytes`]: crate::ptr::write_bytes()
|
||||||
#[doc(alias = "memset")]
|
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
//#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[doc(alias = "memset")]
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
|
||||||
pub const unsafe fn write_bytes(self, val: u8, count: usize)
|
pub const unsafe fn write_bytes(self, val: u8, count: usize)
|
||||||
where
|
where
|
||||||
T: Sized,
|
T: Sized,
|
||||||
@ -1156,9 +1147,9 @@ pub unsafe fn drop_in_place(self) {
|
|||||||
/// See [`ptr::write_volatile`] for safety concerns and examples.
|
/// See [`ptr::write_volatile`] for safety concerns and examples.
|
||||||
///
|
///
|
||||||
/// [`ptr::write_volatile`]: crate::ptr::write_volatile()
|
/// [`ptr::write_volatile`]: crate::ptr::write_volatile()
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub unsafe fn write_volatile(self, val: T)
|
pub unsafe fn write_volatile(self, val: T)
|
||||||
where
|
where
|
||||||
T: Sized,
|
T: Sized,
|
||||||
@ -1175,11 +1166,10 @@ pub unsafe fn write_volatile(self, val: T)
|
|||||||
/// See [`ptr::write_unaligned`] for safety concerns and examples.
|
/// See [`ptr::write_unaligned`] for safety concerns and examples.
|
||||||
///
|
///
|
||||||
/// [`ptr::write_unaligned`]: crate::ptr::write_unaligned()
|
/// [`ptr::write_unaligned`]: crate::ptr::write_unaligned()
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
//#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
|
||||||
pub const unsafe fn write_unaligned(self, val: T)
|
pub const unsafe fn write_unaligned(self, val: T)
|
||||||
where
|
where
|
||||||
T: Sized,
|
T: Sized,
|
||||||
@ -1194,8 +1184,8 @@ pub unsafe fn write_volatile(self, val: T)
|
|||||||
/// See [`ptr::replace`] for safety concerns and examples.
|
/// See [`ptr::replace`] for safety concerns and examples.
|
||||||
///
|
///
|
||||||
/// [`ptr::replace`]: crate::ptr::replace()
|
/// [`ptr::replace`]: crate::ptr::replace()
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
pub unsafe fn replace(self, src: T) -> T
|
pub unsafe fn replace(self, src: T) -> T
|
||||||
where
|
where
|
||||||
T: Sized,
|
T: Sized,
|
||||||
@ -1211,10 +1201,9 @@ pub unsafe fn replace(self, src: T) -> T
|
|||||||
/// See [`ptr::swap`] for safety concerns and examples.
|
/// See [`ptr::swap`] for safety concerns and examples.
|
||||||
///
|
///
|
||||||
/// [`ptr::swap`]: crate::ptr::swap()
|
/// [`ptr::swap`]: crate::ptr::swap()
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
//#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
|
||||||
pub const unsafe fn swap(self, with: NonNull<T>)
|
pub const unsafe fn swap(self, with: NonNull<T>)
|
||||||
where
|
where
|
||||||
T: Sized,
|
T: Sized,
|
||||||
@ -1246,7 +1235,6 @@ pub unsafe fn replace(self, src: T) -> T
|
|||||||
/// Accessing adjacent `u8` as `u16`
|
/// Accessing adjacent `u8` as `u16`
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(non_null_convenience)]
|
|
||||||
/// use std::mem::align_of;
|
/// use std::mem::align_of;
|
||||||
/// use std::ptr::NonNull;
|
/// use std::ptr::NonNull;
|
||||||
///
|
///
|
||||||
@ -1264,11 +1252,10 @@ pub unsafe fn replace(self, src: T) -> T
|
|||||||
/// }
|
/// }
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
#[rustc_const_unstable(feature = "non_null_convenience", issue = "117691")]
|
|
||||||
//#[rustc_const_unstable(feature = "const_align_offset", issue = "90962")]
|
|
||||||
#[must_use]
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
|
#[stable(feature = "non_null_convenience", since = "CURRENT_RUSTC_VERSION")]
|
||||||
|
#[rustc_const_unstable(feature = "const_align_offset", issue = "90962")]
|
||||||
pub const fn align_offset(self, align: usize) -> usize
|
pub const fn align_offset(self, align: usize) -> usize
|
||||||
where
|
where
|
||||||
T: Sized,
|
T: Sized,
|
||||||
@ -1312,10 +1299,9 @@ pub const fn align_offset(self, align: usize) -> usize
|
|||||||
/// underlying allocation.
|
/// underlying allocation.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(const_pointer_is_aligned)]
|
|
||||||
/// #![feature(non_null_convenience)]
|
|
||||||
/// #![feature(const_option)]
|
|
||||||
/// #![feature(const_nonnull_new)]
|
/// #![feature(const_nonnull_new)]
|
||||||
|
/// #![feature(const_option)]
|
||||||
|
/// #![feature(const_pointer_is_aligned)]
|
||||||
/// use std::ptr::NonNull;
|
/// use std::ptr::NonNull;
|
||||||
///
|
///
|
||||||
/// // On some platforms, the alignment of primitives is less than their size.
|
/// // On some platforms, the alignment of primitives is less than their size.
|
||||||
@ -1390,10 +1376,10 @@ pub const fn align_offset(self, align: usize) -> usize
|
|||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
|
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
|
||||||
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
#[stable(feature = "pointer_is_aligned", since = "CURRENT_RUSTC_VERSION")]
|
#[stable(feature = "pointer_is_aligned", since = "CURRENT_RUSTC_VERSION")]
|
||||||
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
|
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
|
||||||
#[must_use]
|
|
||||||
#[inline]
|
|
||||||
pub const fn is_aligned(self) -> bool
|
pub const fn is_aligned(self) -> bool
|
||||||
where
|
where
|
||||||
T: Sized,
|
T: Sized,
|
||||||
@ -1505,10 +1491,10 @@ pub const fn is_aligned(self) -> bool
|
|||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
|
/// [tracking issue]: https://github.com/rust-lang/rust/issues/104203
|
||||||
|
#[inline]
|
||||||
|
#[must_use]
|
||||||
#[unstable(feature = "pointer_is_aligned_to", issue = "96284")]
|
#[unstable(feature = "pointer_is_aligned_to", issue = "96284")]
|
||||||
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
|
#[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")]
|
||||||
#[must_use]
|
|
||||||
#[inline]
|
|
||||||
pub const fn is_aligned_to(self, align: usize) -> bool {
|
pub const fn is_aligned_to(self, align: usize) -> bool {
|
||||||
self.pointer.is_aligned_to(align)
|
self.pointer.is_aligned_to(align)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user