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 f2becdf

Browse files
committedSep 26, 2024
Auto merge of #130865 - cuviper:library-raw_ref_op, r=tgross35
Use `&raw` in the standard library Since the stabilization in #127679 has reached stage0, 1.82-beta, we can start using `&raw` freely, and even the soft-deprecated `ptr::addr_of!` and `ptr::addr_of_mut!` can stop allowing the unstable feature. I intentionally did not change any documentation or tests, but the rest of those macro uses are all now using `&raw const` or `&raw mut` in the standard library.
2 parents 76ed7a1 + f4d9d1a commit f2becdf

File tree

51 files changed

+150
-185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+150
-185
lines changed
 

‎library/alloc/src/boxed.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ use core::ops::{
199199
DerefPure, DispatchFromDyn, Receiver,
200200
};
201201
use core::pin::{Pin, PinCoerceUnsized};
202-
use core::ptr::{self, NonNull, Unique, addr_of_mut};
202+
use core::ptr::{self, NonNull, Unique};
203203
use core::task::{Context, Poll};
204204
use core::{borrow, fmt, slice};
205205

@@ -1277,7 +1277,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12771277
#[inline]
12781278
pub fn into_raw(b: Self) -> *mut T {
12791279
// Make sure Miri realizes that we transition from a noalias pointer to a raw pointer here.
1280-
unsafe { addr_of_mut!(*&mut *Self::into_raw_with_allocator(b).0) }
1280+
unsafe { &raw mut *&mut *Self::into_raw_with_allocator(b).0 }
12811281
}
12821282

12831283
/// Consumes the `Box`, returning a wrapped `NonNull` pointer.
@@ -1396,7 +1396,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
13961396
// want *no* aliasing requirements here!
13971397
// In case `A` *is* `Global`, this does not quite have the right behavior; `into_raw`
13981398
// works around that.
1399-
let ptr = addr_of_mut!(**b);
1399+
let ptr = &raw mut **b;
14001400
let alloc = unsafe { ptr::read(&b.1) };
14011401
(ptr, alloc)
14021402
}
@@ -1506,7 +1506,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
15061506
pub fn as_mut_ptr(b: &mut Self) -> *mut T {
15071507
// This is a primitive deref, not going through `DerefMut`, and therefore not materializing
15081508
// any references.
1509-
ptr::addr_of_mut!(**b)
1509+
&raw mut **b
15101510
}
15111511

15121512
/// Returns a raw pointer to the `Box`'s contents.
@@ -1554,7 +1554,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
15541554
pub fn as_ptr(b: &Self) -> *const T {
15551555
// This is a primitive deref, not going through `DerefMut`, and therefore not materializing
15561556
// any references.
1557-
ptr::addr_of!(**b)
1557+
&raw const **b
15581558
}
15591559

15601560
/// Returns a reference to the underlying allocator.

‎library/alloc/src/boxed/thin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<T: ?Sized> ThinBox<T> {
186186

187187
fn with_header(&self) -> &WithHeader<<T as Pointee>::Metadata> {
188188
// SAFETY: both types are transparent to `NonNull<u8>`
189-
unsafe { &*(core::ptr::addr_of!(self.ptr) as *const WithHeader<_>) }
189+
unsafe { &*((&raw const self.ptr) as *const WithHeader<_>) }
190190
}
191191
}
192192

0 commit comments

Comments
 (0)
Please sign in to comment.