Skip to content

Fix safety docs for dyn Any + Send {+ Sync} #134662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 24, 2024
Merged
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
14 changes: 12 additions & 2 deletions library/core/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ impl dyn Any + Send {
///
/// # 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")]
#[inline]
pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
Expand Down Expand Up @@ -451,7 +452,8 @@ impl dyn Any + Send {
///
/// # 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")]
#[inline]
pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T {
Expand Down Expand Up @@ -552,6 +554,10 @@ impl dyn Any + Send + Sync {
/// 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")]
#[inline]
pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
Expand All @@ -576,6 +582,10 @@ impl dyn Any + Send + Sync {
///
/// 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")]
#[inline]
pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T {
Expand Down
Loading