Skip to content

Commit 5a2c6d7

Browse files
authored
Rollup merge of rust-lang#67519 - Mark-Simulacrum:any-unsafe, r=Centril
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
2 parents e79fc97 + 6878913 commit 5a2c6d7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/libcore/any.rs

+10
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ use crate::intrinsics;
7474
/// See the [module-level documentation][mod] for more details.
7575
///
7676
/// [mod]: index.html
77+
// This trait is not unsafe, though we rely on the specifics of it's sole impl's
78+
// `type_id` function in unsafe code (e.g., `downcast`). Normally, that would be
79+
// a problem, but because the only impl of `Any` is a blanket implementation, no
80+
// other code can implement `Any`.
81+
//
82+
// We could plausibly make this trait unsafe -- it would not cause breakage,
83+
// since we control all the implementations -- but we choose not to as that's
84+
// both not really necessary and may confuse users about the distinction of
85+
// unsafe traits and unsafe methods (i.e., `type_id` would still be safe to call,
86+
// but we would likely want to indicate as such in documentation).
7787
#[stable(feature = "rust1", since = "1.0.0")]
7888
pub trait Any: 'static {
7989
/// Gets the `TypeId` of `self`.

0 commit comments

Comments
 (0)