Skip to content

Commit

Permalink
Rollup merge of rust-lang#67519 - Mark-Simulacrum:any-unsafe, r=Centril
Browse files Browse the repository at this point in the history
Document why Any is not an unsafe trait

The added documentation is not public (i.e., not in a doc comment) but that seems appropriate for this sort of low-level detail.

Fixes rust-lang#62303
  • Loading branch information
Centril committed Dec 22, 2019
2 parents dd1f3ca + 6878913 commit ab93543
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/libcore/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ use crate::intrinsics;
/// See the [module-level documentation][mod] for more details.
///
/// [mod]: index.html
// This trait is not unsafe, though we rely on the specifics of it's sole impl's
// `type_id` function in unsafe code (e.g., `downcast`). Normally, that would be
// a problem, but because the only impl of `Any` is a blanket implementation, no
// other code can implement `Any`.
//
// We could plausibly make this trait unsafe -- it would not cause breakage,
// since we control all the implementations -- but we choose not to as that's
// both not really necessary and may confuse users about the distinction of
// unsafe traits and unsafe methods (i.e., `type_id` would still be safe to call,
// but we would likely want to indicate as such in documentation).
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Any: 'static {
/// Gets the `TypeId` of `self`.
Expand Down

0 comments on commit ab93543

Please sign in to comment.