Rename downcast_[ref|mut]_unchecked -> downcast_unchecked_[ref|mut]

Undo rust-analyzer changes
This commit is contained in:
Taj Pereira
2025-10-25 06:11:13 +10:30
parent ab925646fa
commit b247f67d64
2 changed files with 19 additions and 19 deletions
+18 -18
View File
@@ -227,7 +227,7 @@ pub fn downcast_ref<T: Any>(&self) -> Option<&T> {
// SAFETY: just checked whether we are pointing to the correct type, and we can rely on
// that check for memory safety because we have implemented Any for all types; no other
// impls can exist as they would conflict with our impl.
unsafe { Some(self.downcast_ref_unchecked()) }
unsafe { Some(self.downcast_unchecked_ref()) }
} else {
None
}
@@ -263,7 +263,7 @@ pub fn downcast_mut<T: Any>(&mut self) -> Option<&mut T> {
// SAFETY: just checked whether we are pointing to the correct type, and we can rely on
// that check for memory safety because we have implemented Any for all types; no other
// impls can exist as they would conflict with our impl.
unsafe { Some(self.downcast_mut_unchecked()) }
unsafe { Some(self.downcast_unchecked_mut()) }
} else {
None
}
@@ -281,7 +281,7 @@ pub fn downcast_mut<T: Any>(&mut self) -> Option<&mut T> {
/// let x: Box<dyn Any> = Box::new(1_usize);
///
/// unsafe {
/// assert_eq!(*x.downcast_ref_unchecked::<usize>(), 1);
/// assert_eq!(*x.downcast_unchecked_ref::<usize>(), 1);
/// }
/// ```
///
@@ -291,7 +291,7 @@ pub fn downcast_mut<T: Any>(&mut self) -> Option<&mut T> {
/// with the incorrect type is *undefined behavior*.
#[unstable(feature = "downcast_unchecked", issue = "90850")]
#[inline]
pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
pub unsafe fn downcast_unchecked_ref<T: Any>(&self) -> &T {
debug_assert!(self.is::<T>());
// SAFETY: caller guarantees that T is the correct type
unsafe { &*(self as *const dyn Any as *const T) }
@@ -309,7 +309,7 @@ pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
/// let mut x: Box<dyn Any> = Box::new(1_usize);
///
/// unsafe {
/// *x.downcast_mut_unchecked::<usize>() += 1;
/// *x.downcast_unchecked_mut::<usize>() += 1;
/// }
///
/// assert_eq!(*x.downcast_ref::<usize>().unwrap(), 2);
@@ -321,7 +321,7 @@ pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
/// with the incorrect type is *undefined behavior*.
#[unstable(feature = "downcast_unchecked", issue = "90850")]
#[inline]
pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T {
pub unsafe fn downcast_unchecked_mut<T: Any>(&mut self) -> &mut T {
debug_assert!(self.is::<T>());
// SAFETY: caller guarantees that T is the correct type
unsafe { &mut *(self as *mut dyn Any as *mut T) }
@@ -417,7 +417,7 @@ pub fn downcast_mut<T: Any>(&mut self) -> Option<&mut T> {
/// let x: Box<dyn Any> = Box::new(1_usize);
///
/// unsafe {
/// assert_eq!(*x.downcast_ref_unchecked::<usize>(), 1);
/// assert_eq!(*x.downcast_unchecked_ref::<usize>(), 1);
/// }
/// ```
///
@@ -427,9 +427,9 @@ pub fn downcast_mut<T: Any>(&mut self) -> Option<&mut T> {
/// with the incorrect type is *undefined behavior*.
#[unstable(feature = "downcast_unchecked", issue = "90850")]
#[inline]
pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
pub unsafe fn downcast_unchecked_ref<T: Any>(&self) -> &T {
// SAFETY: guaranteed by caller
unsafe { <dyn Any>::downcast_ref_unchecked::<T>(self) }
unsafe { <dyn Any>::downcast_unchecked_ref::<T>(self) }
}
/// Forwards to the method defined on the type `dyn Any`.
@@ -444,7 +444,7 @@ pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
/// let mut x: Box<dyn Any> = Box::new(1_usize);
///
/// unsafe {
/// *x.downcast_mut_unchecked::<usize>() += 1;
/// *x.downcast_unchecked_mut::<usize>() += 1;
/// }
///
/// assert_eq!(*x.downcast_ref::<usize>().unwrap(), 2);
@@ -456,9 +456,9 @@ pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
/// with the incorrect type is *undefined behavior*.
#[unstable(feature = "downcast_unchecked", issue = "90850")]
#[inline]
pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T {
pub unsafe fn downcast_unchecked_mut<T: Any>(&mut self) -> &mut T {
// SAFETY: guaranteed by caller
unsafe { <dyn Any>::downcast_mut_unchecked::<T>(self) }
unsafe { <dyn Any>::downcast_unchecked_mut::<T>(self) }
}
}
@@ -551,7 +551,7 @@ pub fn downcast_mut<T: Any>(&mut self) -> Option<&mut T> {
/// let x: Box<dyn Any> = Box::new(1_usize);
///
/// unsafe {
/// assert_eq!(*x.downcast_ref_unchecked::<usize>(), 1);
/// assert_eq!(*x.downcast_unchecked_ref::<usize>(), 1);
/// }
/// ```
/// # Safety
@@ -560,9 +560,9 @@ pub fn downcast_mut<T: Any>(&mut self) -> Option<&mut T> {
/// with the incorrect type is *undefined behavior*.
#[unstable(feature = "downcast_unchecked", issue = "90850")]
#[inline]
pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
pub unsafe fn downcast_unchecked_ref<T: Any>(&self) -> &T {
// SAFETY: guaranteed by caller
unsafe { <dyn Any>::downcast_ref_unchecked::<T>(self) }
unsafe { <dyn Any>::downcast_unchecked_ref::<T>(self) }
}
/// Forwards to the method defined on the type `Any`.
@@ -577,7 +577,7 @@ pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
/// let mut x: Box<dyn Any> = Box::new(1_usize);
///
/// unsafe {
/// *x.downcast_mut_unchecked::<usize>() += 1;
/// *x.downcast_unchecked_mut::<usize>() += 1;
/// }
///
/// assert_eq!(*x.downcast_ref::<usize>().unwrap(), 2);
@@ -588,9 +588,9 @@ pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
/// with the incorrect type is *undefined behavior*.
#[unstable(feature = "downcast_unchecked", issue = "90850")]
#[inline]
pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T {
pub unsafe fn downcast_unchecked_mut<T: Any>(&mut self) -> &mut T {
// SAFETY: guaranteed by caller
unsafe { <dyn Any>::downcast_mut_unchecked::<T>(self) }
unsafe { <dyn Any>::downcast_unchecked_mut::<T>(self) }
}
}
@@ -44,7 +44,7 @@ fn main() {
//~^ ERROR ambiguous associated type [E0223]
//~| HELP if there were a trait named `Example` with associated type `wrapping`
// this one ideally should suggest `downcast_mut_unchecked`
// this one ideally should suggest `downcast_unchecked_mut`
<dyn std::any::Any>::downcast::mut_unchecked;
//~^ ERROR ambiguous associated type [E0223]
//~| HELP if there were a trait named `Example` with associated type `downcast`