Tag relevant functions with #[rustc_as_ptr] attribute
This commit is contained in:
parent
37c30aeb45
commit
fdef65bf6e
7 changed files with 15 additions and 0 deletions
|
@ -1499,6 +1499,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
|
|||
/// [`as_ptr`]: Self::as_ptr
|
||||
#[unstable(feature = "box_as_ptr", issue = "129090")]
|
||||
#[rustc_never_returns_null_ptr]
|
||||
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
|
||||
#[inline]
|
||||
pub fn as_mut_ptr(b: &mut Self) -> *mut T {
|
||||
// This is a primitive deref, not going through `DerefMut`, and therefore not materializing
|
||||
|
@ -1547,6 +1548,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
|
|||
/// [`as_ptr`]: Self::as_ptr
|
||||
#[unstable(feature = "box_as_ptr", issue = "129090")]
|
||||
#[rustc_never_returns_null_ptr]
|
||||
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
|
||||
#[inline]
|
||||
pub fn as_ptr(b: &Self) -> *const T {
|
||||
// This is a primitive deref, not going through `DerefMut`, and therefore not materializing
|
||||
|
|
|
@ -1662,6 +1662,7 @@ impl<T, A: Allocator> Vec<T, A> {
|
|||
#[stable(feature = "vec_as_ptr", since = "1.37.0")]
|
||||
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
|
||||
#[rustc_never_returns_null_ptr]
|
||||
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
|
||||
#[inline]
|
||||
pub const fn as_ptr(&self) -> *const T {
|
||||
// We shadow the slice method of the same name to avoid going through
|
||||
|
@ -1724,6 +1725,7 @@ impl<T, A: Allocator> Vec<T, A> {
|
|||
#[stable(feature = "vec_as_ptr", since = "1.37.0")]
|
||||
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
|
||||
#[rustc_never_returns_null_ptr]
|
||||
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
|
||||
#[inline]
|
||||
pub const fn as_mut_ptr(&mut self) -> *mut T {
|
||||
// We shadow the slice method of the same name to avoid going through
|
||||
|
|
|
@ -587,6 +587,7 @@ impl<T: ?Sized> Cell<T> {
|
|||
#[inline]
|
||||
#[stable(feature = "cell_as_ptr", since = "1.12.0")]
|
||||
#[rustc_const_stable(feature = "const_cell_as_ptr", since = "1.32.0")]
|
||||
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
|
||||
#[rustc_never_returns_null_ptr]
|
||||
pub const fn as_ptr(&self) -> *mut T {
|
||||
self.value.get()
|
||||
|
@ -1149,6 +1150,7 @@ impl<T: ?Sized> RefCell<T> {
|
|||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "cell_as_ptr", since = "1.12.0")]
|
||||
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
|
||||
#[rustc_never_returns_null_ptr]
|
||||
pub fn as_ptr(&self) -> *mut T {
|
||||
self.value.get()
|
||||
|
@ -2157,6 +2159,7 @@ impl<T: ?Sized> UnsafeCell<T> {
|
|||
#[inline(always)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_stable(feature = "const_unsafecell_get", since = "1.32.0")]
|
||||
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
|
||||
#[rustc_never_returns_null_ptr]
|
||||
pub const fn get(&self) -> *mut T {
|
||||
// We can just cast the pointer from `UnsafeCell<T>` to `T` because of
|
||||
|
@ -2303,6 +2306,7 @@ impl<T: ?Sized> SyncUnsafeCell<T> {
|
|||
/// when casting to `&mut T`, and ensure that there are no mutations
|
||||
/// or mutable aliases going on when casting to `&T`
|
||||
#[inline]
|
||||
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
|
||||
#[rustc_never_returns_null_ptr]
|
||||
pub const fn get(&self) -> *mut T {
|
||||
self.value.get()
|
||||
|
|
|
@ -501,6 +501,7 @@ impl CStr {
|
|||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_stable(feature = "const_str_as_ptr", since = "1.32.0")]
|
||||
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
|
||||
#[rustc_never_returns_null_ptr]
|
||||
pub const fn as_ptr(&self) -> *const c_char {
|
||||
self.inner.as_ptr()
|
||||
|
|
|
@ -529,6 +529,7 @@ impl<T> MaybeUninit<T> {
|
|||
/// until they are, it is advisable to avoid them.)
|
||||
#[stable(feature = "maybe_uninit", since = "1.36.0")]
|
||||
#[rustc_const_stable(feature = "const_maybe_uninit_as_ptr", since = "1.59.0")]
|
||||
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
|
||||
#[inline(always)]
|
||||
pub const fn as_ptr(&self) -> *const T {
|
||||
// `MaybeUninit` and `ManuallyDrop` are both `repr(transparent)` so we can cast the pointer.
|
||||
|
@ -570,6 +571,7 @@ impl<T> MaybeUninit<T> {
|
|||
/// until they are, it is advisable to avoid them.)
|
||||
#[stable(feature = "maybe_uninit", since = "1.36.0")]
|
||||
#[rustc_const_stable(feature = "const_maybe_uninit_as_mut_ptr", since = "1.83.0")]
|
||||
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
|
||||
#[inline(always)]
|
||||
pub const fn as_mut_ptr(&mut self) -> *mut T {
|
||||
// `MaybeUninit` and `ManuallyDrop` are both `repr(transparent)` so we can cast the pointer.
|
||||
|
|
|
@ -735,6 +735,7 @@ impl<T> [T] {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_stable(feature = "const_slice_as_ptr", since = "1.32.0")]
|
||||
#[rustc_never_returns_null_ptr]
|
||||
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub const fn as_ptr(&self) -> *const T {
|
||||
|
@ -766,6 +767,7 @@ impl<T> [T] {
|
|||
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
|
||||
#[rustc_allow_const_fn_unstable(const_mut_refs)]
|
||||
#[rustc_never_returns_null_ptr]
|
||||
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub const fn as_mut_ptr(&mut self) -> *mut T {
|
||||
|
|
|
@ -371,6 +371,7 @@ impl str {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_stable(feature = "rustc_str_as_ptr", since = "1.32.0")]
|
||||
#[rustc_never_returns_null_ptr]
|
||||
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
|
||||
#[must_use]
|
||||
#[inline(always)]
|
||||
pub const fn as_ptr(&self) -> *const u8 {
|
||||
|
@ -388,6 +389,7 @@ impl str {
|
|||
#[stable(feature = "str_as_mut_ptr", since = "1.36.0")]
|
||||
#[rustc_const_stable(feature = "const_str_as_mut", since = "1.83.0")]
|
||||
#[rustc_never_returns_null_ptr]
|
||||
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
|
||||
#[must_use]
|
||||
#[inline(always)]
|
||||
pub const fn as_mut_ptr(&mut self) -> *mut u8 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue