Rollup merge of #134662 - ionicmc-rs:any-safety-docs, r=Amanieu

Fix safety docs for `dyn Any + Send {+ Sync}`

Fixes the `# Safety` docs for `dyn Any + Send`'s `downcast_{mut/ref}_unchecked` to show the direct instructions , where previously the would tell the user to find the docs on `dyn Any` themselves.

This also adds them for `downcast_{mut/ref}_unchecked` on `dyn Any + Send + Sync`
This commit is contained in:
Stuart Cook 2024-12-24 14:05:22 +11:00 committed by GitHub
commit 0c93b279ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -423,7 +423,8 @@ impl dyn Any + Send {
/// ///
/// # Safety /// # Safety
/// ///
/// Same as the method on the type `dyn Any`. /// The contained value must be of type `T`. Calling this method
/// with the incorrect type is *undefined behavior*.
#[unstable(feature = "downcast_unchecked", issue = "90850")] #[unstable(feature = "downcast_unchecked", issue = "90850")]
#[inline] #[inline]
pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T { pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
@ -451,7 +452,8 @@ impl dyn Any + Send {
/// ///
/// # Safety /// # Safety
/// ///
/// Same as the method on the type `dyn Any`. /// The contained value must be of type `T`. Calling this method
/// with the incorrect type is *undefined behavior*.
#[unstable(feature = "downcast_unchecked", issue = "90850")] #[unstable(feature = "downcast_unchecked", issue = "90850")]
#[inline] #[inline]
pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T { pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T {
@ -552,6 +554,10 @@ impl dyn Any + Send + Sync {
/// assert_eq!(*x.downcast_ref_unchecked::<usize>(), 1); /// assert_eq!(*x.downcast_ref_unchecked::<usize>(), 1);
/// } /// }
/// ``` /// ```
/// # Safety
///
/// The contained value must be of type `T`. Calling this method
/// with the incorrect type is *undefined behavior*.
#[unstable(feature = "downcast_unchecked", issue = "90850")] #[unstable(feature = "downcast_unchecked", issue = "90850")]
#[inline] #[inline]
pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T { pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
@ -576,6 +582,10 @@ impl dyn Any + Send + Sync {
/// ///
/// assert_eq!(*x.downcast_ref::<usize>().unwrap(), 2); /// assert_eq!(*x.downcast_ref::<usize>().unwrap(), 2);
/// ``` /// ```
/// # Safety
///
/// The contained value must be of type `T`. Calling this method
/// with the incorrect type is *undefined behavior*.
#[unstable(feature = "downcast_unchecked", issue = "90850")] #[unstable(feature = "downcast_unchecked", issue = "90850")]
#[inline] #[inline]
pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T { pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T {