Skip to content

Commit 6e046fe

Browse files
Rollup merge of #120424 - RalfJung:raw-ptr-meta, r=Nilstrieb
raw pointer metadata API: data address -> data pointer A pointer consists of [more than just an address](rust-lang/rfcs#3559), so let's not equate "pointer" and "address" in these docs.
2 parents 8ab372d + b4e1c56 commit 6e046fe

7 files changed

+19
-19
lines changed

library/core/src/ptr/const_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl<T: ?Sized> *const T {
285285
self.with_addr(f(self.addr()))
286286
}
287287

288-
/// Decompose a (possibly wide) pointer into its address and metadata components.
288+
/// Decompose a (possibly wide) pointer into its data pointer and metadata components.
289289
///
290290
/// The pointer can be later reconstructed with [`from_raw_parts`].
291291
#[unstable(feature = "ptr_metadata", issue = "81513")]

library/core/src/ptr/metadata.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ use crate::hash::{Hash, Hasher};
3939
///
4040
/// # Usage
4141
///
42-
/// Raw pointers can be decomposed into the data address and metadata components
42+
/// Raw pointers can be decomposed into the data pointer and metadata components
4343
/// with their [`to_raw_parts`] method.
4444
///
4545
/// Alternatively, metadata alone can be extracted with the [`metadata`] function.
4646
/// A reference can be passed to [`metadata`] and implicitly coerced.
4747
///
48-
/// A (possibly-wide) pointer can be put back together from its address and metadata
48+
/// A (possibly-wide) pointer can be put back together from its data pointer and metadata
4949
/// with [`from_raw_parts`] or [`from_raw_parts_mut`].
5050
///
5151
/// [`to_raw_parts`]: *const::to_raw_parts
@@ -98,7 +98,7 @@ pub const fn metadata<T: ?Sized>(ptr: *const T) -> <T as Pointee>::Metadata {
9898
unsafe { PtrRepr { const_ptr: ptr }.components.metadata }
9999
}
100100

101-
/// Forms a (possibly-wide) raw pointer from a data address and metadata.
101+
/// Forms a (possibly-wide) raw pointer from a data pointer and metadata.
102102
///
103103
/// This function is safe but the returned pointer is not necessarily safe to dereference.
104104
/// For slices, see the documentation of [`slice::from_raw_parts`] for safety requirements.
@@ -109,13 +109,13 @@ pub const fn metadata<T: ?Sized>(ptr: *const T) -> <T as Pointee>::Metadata {
109109
#[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")]
110110
#[inline]
111111
pub const fn from_raw_parts<T: ?Sized>(
112-
data_address: *const (),
112+
data_pointer: *const (),
113113
metadata: <T as Pointee>::Metadata,
114114
) -> *const T {
115115
// SAFETY: Accessing the value from the `PtrRepr` union is safe since *const T
116116
// and PtrComponents<T> have the same memory layouts. Only std can make this
117117
// guarantee.
118-
unsafe { PtrRepr { components: PtrComponents { data_address, metadata } }.const_ptr }
118+
unsafe { PtrRepr { components: PtrComponents { data_pointer, metadata } }.const_ptr }
119119
}
120120

121121
/// Performs the same functionality as [`from_raw_parts`], except that a
@@ -126,13 +126,13 @@ pub const fn from_raw_parts<T: ?Sized>(
126126
#[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")]
127127
#[inline]
128128
pub const fn from_raw_parts_mut<T: ?Sized>(
129-
data_address: *mut (),
129+
data_pointer: *mut (),
130130
metadata: <T as Pointee>::Metadata,
131131
) -> *mut T {
132132
// SAFETY: Accessing the value from the `PtrRepr` union is safe since *const T
133133
// and PtrComponents<T> have the same memory layouts. Only std can make this
134134
// guarantee.
135-
unsafe { PtrRepr { components: PtrComponents { data_address, metadata } }.mut_ptr }
135+
unsafe { PtrRepr { components: PtrComponents { data_pointer, metadata } }.mut_ptr }
136136
}
137137

138138
#[repr(C)]
@@ -144,7 +144,7 @@ union PtrRepr<T: ?Sized> {
144144

145145
#[repr(C)]
146146
struct PtrComponents<T: ?Sized> {
147-
data_address: *const (),
147+
data_pointer: *const (),
148148
metadata: <T as Pointee>::Metadata,
149149
}
150150

library/core/src/ptr/mut_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl<T: ?Sized> *mut T {
292292
self.with_addr(f(self.addr()))
293293
}
294294

295-
/// Decompose a (possibly wide) pointer into its address and metadata components.
295+
/// Decompose a (possibly wide) pointer into its data pointer and metadata components.
296296
///
297297
/// The pointer can be later reconstructed with [`from_raw_parts_mut`].
298298
#[unstable(feature = "ptr_metadata", issue = "81513")]

library/core/src/ptr/non_null.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,16 @@ impl<T: ?Sized> NonNull<T> {
259259
#[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")]
260260
#[inline]
261261
pub const fn from_raw_parts(
262-
data_address: NonNull<()>,
262+
data_pointer: NonNull<()>,
263263
metadata: <T as super::Pointee>::Metadata,
264264
) -> NonNull<T> {
265-
// SAFETY: The result of `ptr::from::raw_parts_mut` is non-null because `data_address` is.
265+
// SAFETY: The result of `ptr::from::raw_parts_mut` is non-null because `data_pointer` is.
266266
unsafe {
267-
NonNull::new_unchecked(super::from_raw_parts_mut(data_address.as_ptr(), metadata))
267+
NonNull::new_unchecked(super::from_raw_parts_mut(data_pointer.as_ptr(), metadata))
268268
}
269269
}
270270

271-
/// Decompose a (possibly wide) pointer into its address and metadata components.
271+
/// Decompose a (possibly wide) pointer into its data pointer and metadata components.
272272
///
273273
/// The pointer can be later reconstructed with [`NonNull::from_raw_parts`].
274274
#[unstable(feature = "ptr_metadata", issue = "81513")]

tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) ->
4242
debug self => _8;
4343
}
4444
scope 15 (inlined std::ptr::from_raw_parts_mut::<[u32]>) {
45-
debug data_address => _9;
45+
debug data_pointer => _9;
4646
debug metadata => _6;
4747
let mut _10: *const ();
4848
let mut _11: std::ptr::metadata::PtrComponents<[u32]>;
@@ -90,7 +90,7 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) ->
9090
StorageLive(_11);
9191
StorageLive(_10);
9292
_10 = _9 as *const () (PointerCoercion(MutToConstPointer));
93-
_11 = std::ptr::metadata::PtrComponents::<[u32]> { data_address: move _10, metadata: _6 };
93+
_11 = std::ptr::metadata::PtrComponents::<[u32]> { data_pointer: move _10, metadata: _6 };
9494
StorageDead(_10);
9595
_12 = std::ptr::metadata::PtrRepr::<[u32]> { const_ptr: move _11 };
9696
StorageDead(_11);

tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) ->
4242
debug self => _8;
4343
}
4444
scope 15 (inlined std::ptr::from_raw_parts_mut::<[u32]>) {
45-
debug data_address => _9;
45+
debug data_pointer => _9;
4646
debug metadata => _6;
4747
let mut _10: *const ();
4848
let mut _11: std::ptr::metadata::PtrComponents<[u32]>;
@@ -90,7 +90,7 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) ->
9090
StorageLive(_11);
9191
StorageLive(_10);
9292
_10 = _9 as *const () (PointerCoercion(MutToConstPointer));
93-
_11 = std::ptr::metadata::PtrComponents::<[u32]> { data_address: move _10, metadata: _6 };
93+
_11 = std::ptr::metadata::PtrComponents::<[u32]> { data_pointer: move _10, metadata: _6 };
9494
StorageDead(_10);
9595
_12 = std::ptr::metadata::PtrRepr::<[u32]> { const_ptr: move _11 };
9696
StorageDead(_11);

tests/ui/union/issue-81199.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ union PtrRepr<T: ?Sized> {
99

1010
#[repr(C)]
1111
struct PtrComponents<T: Pointee + ?Sized> {
12-
data_address: *const (),
12+
data_pointer: *const (),
1313
metadata: <T as Pointee>::Metadata,
1414
}
1515

0 commit comments

Comments
 (0)