Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7707584

Browse files
committedNov 11, 2024
Tag relevant functions with #[rustc_as_ptr] attribute
1 parent 36cfa4e commit 7707584

File tree

7 files changed

+15
-0
lines changed

7 files changed

+15
-0
lines changed
 

‎alloc/src/boxed.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
14991499
/// [`as_ptr`]: Self::as_ptr
15001500
#[unstable(feature = "box_as_ptr", issue = "129090")]
15011501
#[rustc_never_returns_null_ptr]
1502+
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
15021503
#[inline]
15031504
pub fn as_mut_ptr(b: &mut Self) -> *mut T {
15041505
// 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> {
15471548
/// [`as_ptr`]: Self::as_ptr
15481549
#[unstable(feature = "box_as_ptr", issue = "129090")]
15491550
#[rustc_never_returns_null_ptr]
1551+
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
15501552
#[inline]
15511553
pub fn as_ptr(b: &Self) -> *const T {
15521554
// This is a primitive deref, not going through `DerefMut`, and therefore not materializing

‎alloc/src/vec/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,7 @@ impl<T, A: Allocator> Vec<T, A> {
16621662
#[stable(feature = "vec_as_ptr", since = "1.37.0")]
16631663
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
16641664
#[rustc_never_returns_null_ptr]
1665+
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
16651666
#[inline]
16661667
pub const fn as_ptr(&self) -> *const T {
16671668
// We shadow the slice method of the same name to avoid going through
@@ -1724,6 +1725,7 @@ impl<T, A: Allocator> Vec<T, A> {
17241725
#[stable(feature = "vec_as_ptr", since = "1.37.0")]
17251726
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
17261727
#[rustc_never_returns_null_ptr]
1728+
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
17271729
#[inline]
17281730
pub const fn as_mut_ptr(&mut self) -> *mut T {
17291731
// We shadow the slice method of the same name to avoid going through

‎core/src/cell.rs

+4
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ impl<T: ?Sized> Cell<T> {
587587
#[inline]
588588
#[stable(feature = "cell_as_ptr", since = "1.12.0")]
589589
#[rustc_const_stable(feature = "const_cell_as_ptr", since = "1.32.0")]
590+
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
590591
#[rustc_never_returns_null_ptr]
591592
pub const fn as_ptr(&self) -> *mut T {
592593
self.value.get()
@@ -1149,6 +1150,7 @@ impl<T: ?Sized> RefCell<T> {
11491150
/// ```
11501151
#[inline]
11511152
#[stable(feature = "cell_as_ptr", since = "1.12.0")]
1153+
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
11521154
#[rustc_never_returns_null_ptr]
11531155
pub fn as_ptr(&self) -> *mut T {
11541156
self.value.get()
@@ -2157,6 +2159,7 @@ impl<T: ?Sized> UnsafeCell<T> {
21572159
#[inline(always)]
21582160
#[stable(feature = "rust1", since = "1.0.0")]
21592161
#[rustc_const_stable(feature = "const_unsafecell_get", since = "1.32.0")]
2162+
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
21602163
#[rustc_never_returns_null_ptr]
21612164
pub const fn get(&self) -> *mut T {
21622165
// We can just cast the pointer from `UnsafeCell<T>` to `T` because of
@@ -2303,6 +2306,7 @@ impl<T: ?Sized> SyncUnsafeCell<T> {
23032306
/// when casting to `&mut T`, and ensure that there are no mutations
23042307
/// or mutable aliases going on when casting to `&T`
23052308
#[inline]
2309+
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
23062310
#[rustc_never_returns_null_ptr]
23072311
pub const fn get(&self) -> *mut T {
23082312
self.value.get()

‎core/src/ffi/c_str.rs

+1
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ impl CStr {
501501
#[must_use]
502502
#[stable(feature = "rust1", since = "1.0.0")]
503503
#[rustc_const_stable(feature = "const_str_as_ptr", since = "1.32.0")]
504+
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
504505
#[rustc_never_returns_null_ptr]
505506
pub const fn as_ptr(&self) -> *const c_char {
506507
self.inner.as_ptr()

‎core/src/mem/maybe_uninit.rs

+2
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ impl<T> MaybeUninit<T> {
529529
/// until they are, it is advisable to avoid them.)
530530
#[stable(feature = "maybe_uninit", since = "1.36.0")]
531531
#[rustc_const_stable(feature = "const_maybe_uninit_as_ptr", since = "1.59.0")]
532+
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
532533
#[inline(always)]
533534
pub const fn as_ptr(&self) -> *const T {
534535
// `MaybeUninit` and `ManuallyDrop` are both `repr(transparent)` so we can cast the pointer.
@@ -570,6 +571,7 @@ impl<T> MaybeUninit<T> {
570571
/// until they are, it is advisable to avoid them.)
571572
#[stable(feature = "maybe_uninit", since = "1.36.0")]
572573
#[rustc_const_stable(feature = "const_maybe_uninit_as_mut_ptr", since = "1.83.0")]
574+
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
573575
#[inline(always)]
574576
pub const fn as_mut_ptr(&mut self) -> *mut T {
575577
// `MaybeUninit` and `ManuallyDrop` are both `repr(transparent)` so we can cast the pointer.

‎core/src/slice/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ impl<T> [T] {
735735
#[stable(feature = "rust1", since = "1.0.0")]
736736
#[rustc_const_stable(feature = "const_slice_as_ptr", since = "1.32.0")]
737737
#[rustc_never_returns_null_ptr]
738+
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
738739
#[inline(always)]
739740
#[must_use]
740741
pub const fn as_ptr(&self) -> *const T {
@@ -766,6 +767,7 @@ impl<T> [T] {
766767
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
767768
#[rustc_allow_const_fn_unstable(const_mut_refs)]
768769
#[rustc_never_returns_null_ptr]
770+
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
769771
#[inline(always)]
770772
#[must_use]
771773
pub const fn as_mut_ptr(&mut self) -> *mut T {

‎core/src/str/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ impl str {
371371
#[stable(feature = "rust1", since = "1.0.0")]
372372
#[rustc_const_stable(feature = "rustc_str_as_ptr", since = "1.32.0")]
373373
#[rustc_never_returns_null_ptr]
374+
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
374375
#[must_use]
375376
#[inline(always)]
376377
pub const fn as_ptr(&self) -> *const u8 {
@@ -388,6 +389,7 @@ impl str {
388389
#[stable(feature = "str_as_mut_ptr", since = "1.36.0")]
389390
#[rustc_const_stable(feature = "const_str_as_mut", since = "1.83.0")]
390391
#[rustc_never_returns_null_ptr]
392+
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
391393
#[must_use]
392394
#[inline(always)]
393395
pub const fn as_mut_ptr(&mut self) -> *mut u8 {

0 commit comments

Comments
 (0)
Failed to load comments.