diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-22 19:46:16 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-22 19:46:16 +0100 |
| commit | ce6f0b0a1ee8e3766cdf4c63ed8377dea8dea46b (patch) | |
| tree | ffb43132e5dae149774e9fc10d42dcab8c16c89a /src | |
| parent | 63d480a07fd447303321d77a285e1024a1276d43 (diff) | |
| parent | 687891309659fd2942f4c8bc8f9fd2feaf85d864 (diff) | |
| download | rust-ce6f0b0a1ee8e3766cdf4c63ed8377dea8dea46b.tar.gz rust-ce6f0b0a1ee8e3766cdf4c63ed8377dea8dea46b.zip | |
Rollup merge of #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 #62303
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/any.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libcore/any.rs b/src/libcore/any.rs index a2aa6b3fea5..5126fe01a3f 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -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`. |
