4949use alloc:: boxed:: Box ;
5050use core:: any:: Any ;
5151use core:: mem:: { self , ManuallyDrop } ;
52- use core:: ptr;
52+ use core:: ptr:: { addr_of , addr_of_mut } ;
5353use libc:: { c_int, c_uint, c_void} ;
5454
5555// NOTE(nbdd0121): The `canary` field is part of stable ABI.
@@ -135,7 +135,7 @@ mod imp {
135135 macro_rules! ptr {
136136 ( 0 ) => ( 0 ) ;
137137 ( $e: expr) => {
138- ( ( $e as usize ) - ( & imp:: __ImageBase as * const _ as usize ) ) as u32
138+ ( ( $e as usize ) - ( addr_of! ( imp:: __ImageBase) as usize ) ) as u32
139139 }
140140 }
141141}
@@ -220,7 +220,7 @@ extern "C" {
220220// This is fine since the MSVC runtime uses string comparison on the type name
221221// to match TypeDescriptors rather than pointer equality.
222222static mut TYPE_DESCRIPTOR : _TypeDescriptor = _TypeDescriptor {
223- pVFTable : unsafe { & TYPE_INFO_VTABLE } as * const _ as * const _ ,
223+ pVFTable : unsafe { addr_of ! ( TYPE_INFO_VTABLE ) } as * const _ ,
224224 spare : core:: ptr:: null_mut ( ) ,
225225 name : TYPE_NAME ,
226226} ;
@@ -261,9 +261,6 @@ cfg_if::cfg_if! {
261261 }
262262}
263263
264- // FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
265- #[ cfg_attr( bootstrap, allow( static_mut_ref) ) ]
266- #[ cfg_attr( not( bootstrap) , allow( static_mut_refs) ) ]
267264pub unsafe fn panic ( data : Box < dyn Any + Send > ) -> u32 {
268265 use core:: intrinsics:: atomic_store_seqcst;
269266
@@ -274,8 +271,9 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
274271 // The ManuallyDrop is needed here since we don't want Exception to be
275272 // dropped when unwinding. Instead it will be dropped by exception_cleanup
276273 // which is invoked by the C++ runtime.
277- let mut exception = ManuallyDrop :: new ( Exception { canary : & TYPE_DESCRIPTOR , data : Some ( data) } ) ;
278- let throw_ptr = & mut exception as * mut _ as * mut _ ;
274+ let mut exception =
275+ ManuallyDrop :: new ( Exception { canary : addr_of ! ( TYPE_DESCRIPTOR ) , data : Some ( data) } ) ;
276+ let throw_ptr = addr_of_mut ! ( exception) as * mut _ ;
279277
280278 // This... may seems surprising, and justifiably so. On 32-bit MSVC the
281279 // pointers between these structure are just that, pointers. On 64-bit MSVC,
@@ -298,45 +296,42 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
298296 // In any case, we basically need to do something like this until we can
299297 // express more operations in statics (and we may never be able to).
300298 atomic_store_seqcst (
301- & mut THROW_INFO . pmfnUnwind as * mut _ as * mut u32 ,
299+ addr_of_mut ! ( THROW_INFO . pmfnUnwind) as * mut u32 ,
302300 ptr ! ( exception_cleanup) as u32 ,
303301 ) ;
304302 atomic_store_seqcst (
305- & mut THROW_INFO . pCatchableTypeArray as * mut _ as * mut u32 ,
306- ptr ! ( & CATCHABLE_TYPE_ARRAY as * const _ ) as u32 ,
303+ addr_of_mut ! ( THROW_INFO . pCatchableTypeArray) as * mut u32 ,
304+ ptr ! ( addr_of! ( CATCHABLE_TYPE_ARRAY ) ) as u32 ,
307305 ) ;
308306 atomic_store_seqcst (
309- & mut CATCHABLE_TYPE_ARRAY . arrayOfCatchableTypes [ 0 ] as * mut _ as * mut u32 ,
310- ptr ! ( & CATCHABLE_TYPE as * const _ ) as u32 ,
307+ addr_of_mut ! ( CATCHABLE_TYPE_ARRAY . arrayOfCatchableTypes[ 0 ] ) as * mut u32 ,
308+ ptr ! ( addr_of! ( CATCHABLE_TYPE ) ) as u32 ,
311309 ) ;
312310 atomic_store_seqcst (
313- & mut CATCHABLE_TYPE . pType as * mut _ as * mut u32 ,
314- ptr ! ( & TYPE_DESCRIPTOR as * const _ ) as u32 ,
311+ addr_of_mut ! ( CATCHABLE_TYPE . pType) as * mut u32 ,
312+ ptr ! ( addr_of! ( TYPE_DESCRIPTOR ) ) as u32 ,
315313 ) ;
316314 atomic_store_seqcst (
317- & mut CATCHABLE_TYPE . copyFunction as * mut _ as * mut u32 ,
315+ addr_of_mut ! ( CATCHABLE_TYPE . copyFunction) as * mut u32 ,
318316 ptr ! ( exception_copy) as u32 ,
319317 ) ;
320318
321319 extern "system-unwind" {
322320 fn _CxxThrowException ( pExceptionObject : * mut c_void , pThrowInfo : * mut u8 ) -> !;
323321 }
324322
325- _CxxThrowException ( throw_ptr, & mut THROW_INFO as * mut _ as * mut _ ) ;
323+ _CxxThrowException ( throw_ptr, addr_of_mut ! ( THROW_INFO ) as * mut _ ) ;
326324}
327325
328- // FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
329- #[ cfg_attr( bootstrap, allow( static_mut_ref) ) ]
330- #[ cfg_attr( not( bootstrap) , allow( static_mut_refs) ) ]
331326pub unsafe fn cleanup ( payload : * mut u8 ) -> Box < dyn Any + Send > {
332327 // A null payload here means that we got here from the catch (...) of
333328 // __rust_try. This happens when a non-Rust foreign exception is caught.
334329 if payload. is_null ( ) {
335330 super :: __rust_foreign_exception ( ) ;
336331 }
337332 let exception = payload as * mut Exception ;
338- let canary = ptr :: addr_of!( ( * exception) . canary) . read ( ) ;
339- if !ptr:: eq ( canary, & TYPE_DESCRIPTOR ) {
333+ let canary = addr_of ! ( ( * exception) . canary) . read ( ) ;
334+ if !core :: ptr:: eq ( canary, addr_of ! ( TYPE_DESCRIPTOR ) ) {
340335 // A foreign Rust exception.
341336 super :: __rust_foreign_exception ( ) ;
342337 }
0 commit comments