File tree 1 file changed +6
-2
lines changed
1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -194,7 +194,9 @@ impl dyn Any {
194
194
#[ inline]
195
195
pub fn downcast_ref < T : Any > ( & self ) -> Option < & T > {
196
196
if self . is :: < T > ( ) {
197
- // SAFETY: just checked whether we are pointing to the correct type
197
+ // SAFETY: just checked whether we are pointing to the correct type, and we can rely on
198
+ // that check for memory safety because we have implemented Any for all types; no other
199
+ // impls can exist as they would conflict with our impl.
198
200
unsafe { Some ( & * ( self as * const dyn Any as * const T ) ) }
199
201
} else {
200
202
None
@@ -228,7 +230,9 @@ impl dyn Any {
228
230
#[ inline]
229
231
pub fn downcast_mut < T : Any > ( & mut self ) -> Option < & mut T > {
230
232
if self . is :: < T > ( ) {
231
- // SAFETY: just checked whether we are pointing to the correct type
233
+ // SAFETY: just checked whether we are pointing to the correct type, and we can rely on
234
+ // that check for memory safety because we have implemented Any for all types; no other
235
+ // impls can exist as they would conflict with our impl.
232
236
unsafe { Some ( & mut * ( self as * mut dyn Any as * mut T ) ) }
233
237
} else {
234
238
None
You can’t perform that action at this time.
0 commit comments