Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions library/core/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl dyn Any {
// 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
}
Expand Down Expand Up @@ -263,7 +263,7 @@ impl dyn Any {
// 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
}
Expand All @@ -281,7 +281,7 @@ impl dyn Any {
/// 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);
/// }
/// ```
///
Expand All @@ -291,7 +291,7 @@ impl dyn Any {
/// 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) }
Expand All @@ -309,7 +309,7 @@ impl dyn Any {
/// 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);
Expand All @@ -321,7 +321,7 @@ impl dyn Any {
/// 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) }
Expand Down Expand Up @@ -417,7 +417,7 @@ impl dyn Any + Send {
/// 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);
/// }
/// ```
///
Expand All @@ -427,9 +427,9 @@ impl dyn Any + Send {
/// 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`.
Expand All @@ -444,7 +444,7 @@ impl dyn Any + Send {
/// 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);
Expand All @@ -456,9 +456,9 @@ impl dyn Any + Send {
/// 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) }
}
}

Expand Down Expand Up @@ -551,7 +551,7 @@ impl dyn Any + Send + Sync {
/// 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
Expand All @@ -560,9 +560,9 @@ impl dyn Any + Send + Sync {
/// 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`.
Expand All @@ -577,7 +577,7 @@ impl dyn Any + Send + Sync {
/// 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);
Expand All @@ -588,9 +588,9 @@ impl dyn Any + Send + Sync {
/// 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) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
Loading