File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -194,7 +194,9 @@ impl dyn Any {
194194 #[ inline]
195195 pub fn downcast_ref < T : Any > ( & self ) -> Option < & T > {
196196 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.
198200 unsafe { Some ( & * ( self as * const dyn Any as * const T ) ) }
199201 } else {
200202 None
@@ -228,7 +230,9 @@ impl dyn Any {
228230 #[ inline]
229231 pub fn downcast_mut < T : Any > ( & mut self ) -> Option < & mut T > {
230232 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.
232236 unsafe { Some ( & mut * ( self as * mut dyn Any as * mut T ) ) }
233237 } else {
234238 None
You can’t perform that action at this time.
0 commit comments