From eb5acc9b9b520092cc667a810a18498b28d052ab Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Thu, 16 Jun 2022 19:47:24 +0200 Subject: [PATCH] Rename `<*{mut,const} T>::as_{const,mut}` to `cast_` This renames the methods to use the `cast_` prefix instead of `as_` to make it more readable and avoid confusion with `<*mut T>::as_mut()` which is `unsafe` and returns a reference. See #92675 --- library/core/src/ptr/const_ptr.rs | 2 +- library/core/src/ptr/mut_ptr.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 74aa0d9c7bcb2..55f781ce0222a 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -97,7 +97,7 @@ impl *const T { /// refactored. #[unstable(feature = "ptr_const_cast", issue = "92675")] #[rustc_const_unstable(feature = "ptr_const_cast", issue = "92675")] - pub const fn as_mut(self) -> *mut T { + pub const fn cast_mut(self) -> *mut T { self as _ } diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index b988090f4bc4c..27e8b20b3c52d 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -96,11 +96,13 @@ impl *mut T { /// refactored. /// /// While not strictly required (`*mut T` coerces to `*const T`), this is provided for symmetry - /// with `as_mut()` on `*const T` and may have documentation value if used instead of implicit + /// with [`cast_mut`] on `*const T` and may have documentation value if used instead of implicit /// coercion. + /// + /// [`cast_mut`]: #method.cast_mut #[unstable(feature = "ptr_const_cast", issue = "92675")] #[rustc_const_unstable(feature = "ptr_const_cast", issue = "92675")] - pub const fn as_const(self) -> *const T { + pub const fn cast_const(self) -> *const T { self as _ } @@ -289,7 +291,7 @@ impl *mut T { /// For the mutable counterpart see [`as_mut`]. /// /// [`as_uninit_ref`]: #method.as_uninit_ref-1 - /// [`as_mut`]: #method.as_mut-1 + /// [`as_mut`]: #method.as_mut /// /// # Safety ///