@@ -133,28 +133,9 @@ impl<T: ?Sized> *mut T {
133133 self as _
134134 }
135135
136- /// Gets the "address" portion of the pointer.
137- ///
138- /// This is similar to `self as usize`, except that the [provenance][crate::ptr#provenance] of
139- /// the pointer is discarded and not [exposed][crate::ptr#exposed-provenance]. This means that
140- /// casting the returned address back to a pointer yields a [pointer without
141- /// provenance][without_provenance_mut], which is undefined behavior to dereference. To properly
142- /// restore the lost information and obtain a dereferenceable pointer, use
143- /// [`with_addr`][pointer::with_addr] or [`map_addr`][pointer::map_addr].
144- ///
145- /// If using those APIs is not possible because there is no way to preserve a pointer with the
146- /// required provenance, then Strict Provenance might not be for you. Use pointer-integer casts
147- /// or [`expose_provenance`][pointer::expose_provenance] and [`with_exposed_provenance`][with_exposed_provenance]
148- /// instead. However, note that this makes your code less portable and less amenable to tools
149- /// that check for compliance with the Rust memory model.
150- ///
151- /// On most platforms this will produce a value with the same bytes as the original
152- /// pointer, because all the bytes are dedicated to describing the address.
153- /// Platforms which need to store additional information in the pointer may
154- /// perform a change of representation to produce a value containing only the address
155- /// portion of the pointer. What that means is up to the platform to define.
136+ #[ doc = include_str ! ( "./docs/addr.md" ) ]
156137 ///
157- /// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
138+ /// [without_provenance]: without_provenance_mut
158139 #[ must_use]
159140 #[ inline( always) ]
160141 #[ stable( feature = "strict_provenance" , since = "1.84.0" ) ]
@@ -241,26 +222,16 @@ impl<T: ?Sized> *mut T {
241222 ( self . cast ( ) , super :: metadata ( self ) )
242223 }
243224
244- /// Returns `None` if the pointer is null, or else returns a shared reference to
245- /// the value wrapped in `Some`. If the value may be uninitialized, [`as_uninit_ref`]
246- /// must be used instead.
247- ///
248- /// For the mutable counterpart see [`as_mut`].
225+ #[ doc = include_str ! ( "./docs/as_ref.md" ) ]
249226 ///
250- /// [`as_uninit_ref`]: pointer#method.as_uninit_ref-1
251- /// [`as_mut`]: #method.as_mut
252- ///
253- /// # Safety
254- ///
255- /// When calling this method, you have to ensure that *either* the pointer is null *or*
256- /// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
257- ///
258- /// # Panics during const evaluation
259- ///
260- /// This method will panic during const evaluation if the pointer cannot be
261- /// determined to be null or not. See [`is_null`] for more information.
227+ /// ```
228+ /// let ptr: *mut u8 = &mut 10u8 as *mut u8;
262229 ///
263- /// [`is_null`]: #method.is_null-1
230+ /// unsafe {
231+ /// let val_back = &*ptr;
232+ /// println!("We got back the value: {val_back}!");
233+ /// }
234+ /// ```
264235 ///
265236 /// # Examples
266237 ///
@@ -274,20 +245,14 @@ impl<T: ?Sized> *mut T {
274245 /// }
275246 /// ```
276247 ///
277- /// # Null-unchecked version
278- ///
279- /// If you are sure the pointer can never be null and are looking for some kind of
280- /// `as_ref_unchecked` that returns the `&T` instead of `Option<&T>`, know that you can
281- /// dereference the pointer directly.
248+ /// # See Also
282249 ///
283- /// ```
284- /// let ptr: *mut u8 = &mut 10u8 as *mut u8;
250+ /// For the mutable counterpart see [`as_mut`].
285251 ///
286- /// unsafe {
287- /// let val_back = &*ptr;
288- /// println!("We got back the value: {val_back}!");
289- /// }
290- /// ```
252+ /// [`is_null`]: #method.is_null-1
253+ /// [`as_uninit_ref`]: pointer#method.as_uninit_ref-1
254+ /// [`as_mut`]: #method.as_mut
255+
291256 #[ stable( feature = "ptr_as_ref" , since = "1.9.0" ) ]
292257 #[ rustc_const_stable( feature = "const_ptr_is_null" , since = "1.84.0" ) ]
293258 #[ inline]
@@ -330,28 +295,15 @@ impl<T: ?Sized> *mut T {
330295 unsafe { & * self }
331296 }
332297
333- /// Returns `None` if the pointer is null, or else returns a shared reference to
334- /// the value wrapped in `Some`. In contrast to [`as_ref`], this does not require
335- /// that the value has to be initialized.
336- ///
337- /// For the mutable counterpart see [`as_uninit_mut`].
298+ #[ doc = include_str ! ( "./docs/as_uninit_ref.md" ) ]
338299 ///
300+ /// [`is_null`]: #method.is_null-1
339301 /// [`as_ref`]: pointer#method.as_ref-1
340- /// [`as_uninit_mut`]: #method.as_uninit_mut
341- ///
342- /// # Safety
343- ///
344- /// When calling this method, you have to ensure that *either* the pointer is null *or*
345- /// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
346- /// Note that because the created reference is to `MaybeUninit<T>`, the
347- /// source pointer can point to uninitialized memory.
348- ///
349- /// # Panics during const evaluation
350302 ///
351- /// This method will panic during const evaluation if the pointer cannot be
352- /// determined to be null or not. See [`is_null`] for more information .
303+ /// # See Also
304+ /// For the mutable counterpart see [`as_uninit_mut`] .
353305 ///
354- /// [`is_null `]: #method.is_null-1
306+ /// [`as_uninit_mut `]: #method.as_uninit_mut
355307 ///
356308 /// # Examples
357309 ///
0 commit comments