about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-01-29 13:40:58 +0000
committerbors <bors@rust-lang.org>2020-01-29 13:40:58 +0000
commiteed12bcd0cb281979c4c9ed956b9e41fda2bfaeb (patch)
treefdf73820fb17548b3ae1a65849819d42d1783dd5 /src/libcore
parentedb368491551a77d77a48446d4ee88b35490c565 (diff)
parent50df7880a77912702de51f454e58ae65a48d9e29 (diff)
downloadrust-eed12bcd0cb281979c4c9ed956b9e41fda2bfaeb.tar.gz
rust-eed12bcd0cb281979c4c9ed956b9e41fda2bfaeb.zip
Auto merge of #68635 - JohnTitor:rollup-jsc34ac, r=JohnTitor
Rollup of 7 pull requests

Successful merges:

 - #67722 (Minor: note how Any is an unsafe trait in SAFETY comments)
 - #68586 (Make conflicting_repr_hints a deny-by-default c-future-compat lint)
 - #68598 (Fix null synthetic_implementors error)
 - #68603 (Changelog: Demonstrate final build-override syntax)
 - #68609 (Set lld flavor for MSVC to link.exe)
 - #68611 (Correct ICE caused by macros generating invalid spans.)
 - #68627 (Document that write_all will not call write if given an empty buffer)

Failed merges:

r? @ghost
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/any.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/libcore/any.rs b/src/libcore/any.rs
index af02e84d3fa..97ef513cbcc 100644
--- a/src/libcore/any.rs
+++ b/src/libcore/any.rs
@@ -194,7 +194,9 @@ impl dyn Any {
     #[inline]
     pub fn downcast_ref<T: Any>(&self) -> Option<&T> {
         if self.is::<T>() {
-            // SAFETY: just checked whether we are pointing to the correct type
+            // SAFETY: just checked whether we are pointing to the correct type, and we can rely on
+            // that check for memory safety because we have implemented Any for all types; no other
+            // impls can exist as they would conflict with our impl.
             unsafe { Some(&*(self as *const dyn Any as *const T)) }
         } else {
             None
@@ -228,7 +230,9 @@ impl dyn Any {
     #[inline]
     pub fn downcast_mut<T: Any>(&mut self) -> Option<&mut T> {
         if self.is::<T>() {
-            // SAFETY: just checked whether we are pointing to the correct type
+            // SAFETY: just checked whether we are pointing to the correct type, and we can rely on
+            // that check for memory safety because we have implemented Any for all types; no other
+            // impls can exist as they would conflict with our impl.
             unsafe { Some(&mut *(self as *mut dyn Any as *mut T)) }
         } else {
             None