@@ -1886,10 +1886,10 @@ impl<T: ?Sized> Rc<T> {
18861886 // Initialize the RcBox
18871887 let inner = mem_to_rcbox ( ptr. as_non_null_ptr ( ) . as_ptr ( ) ) ;
18881888 unsafe {
1889- debug_assert_eq ! ( Layout :: for_value ( & * inner) , layout) ;
1889+ debug_assert_eq ! ( Layout :: for_value_raw ( inner) , layout) ;
18901890
1891- ptr:: write ( & mut ( * inner) . strong , Cell :: new ( 1 ) ) ;
1892- ptr:: write ( & mut ( * inner) . weak , Cell :: new ( 1 ) ) ;
1891+ ptr:: addr_of_mut! ( ( * inner) . strong) . write ( Cell :: new ( 1 ) ) ;
1892+ ptr:: addr_of_mut! ( ( * inner) . weak) . write ( Cell :: new ( 1 ) ) ;
18931893 }
18941894
18951895 Ok ( inner)
@@ -1903,7 +1903,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
19031903 // Allocate for the `RcBox<T>` using the given value.
19041904 unsafe {
19051905 Rc :: < T > :: allocate_for_layout (
1906- Layout :: for_value ( & * ptr) ,
1906+ Layout :: for_value_raw ( ptr) ,
19071907 |layout| alloc. allocate ( layout) ,
19081908 |mem| mem. with_metadata_of ( ptr as * const RcBox < T > ) ,
19091909 )
@@ -1919,7 +1919,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
19191919 // Copy value as bytes
19201920 ptr:: copy_nonoverlapping (
19211921 & * src as * const T as * const u8 ,
1922- & mut ( * ptr) . value as * mut _ as * mut u8 ,
1922+ ptr :: addr_of_mut! ( ( * ptr) . value) as * mut u8 ,
19231923 value_size,
19241924 ) ;
19251925
@@ -1953,7 +1953,11 @@ impl<T> Rc<[T]> {
19531953 unsafe fn copy_from_slice ( v : & [ T ] ) -> Rc < [ T ] > {
19541954 unsafe {
19551955 let ptr = Self :: allocate_for_slice ( v. len ( ) ) ;
1956- ptr:: copy_nonoverlapping ( v. as_ptr ( ) , & mut ( * ptr) . value as * mut [ T ] as * mut T , v. len ( ) ) ;
1956+ ptr:: copy_nonoverlapping (
1957+ v. as_ptr ( ) ,
1958+ ptr:: addr_of_mut!( ( * ptr) . value) as * mut T ,
1959+ v. len ( ) ,
1960+ ) ;
19571961 Self :: from_ptr ( ptr)
19581962 }
19591963 }
@@ -1988,10 +1992,10 @@ impl<T> Rc<[T]> {
19881992 let ptr = Self :: allocate_for_slice ( len) ;
19891993
19901994 let mem = ptr as * mut _ as * mut u8 ;
1991- let layout = Layout :: for_value ( & * ptr) ;
1995+ let layout = Layout :: for_value_raw ( ptr) ;
19921996
19931997 // Pointer to first element
1994- let elems = & mut ( * ptr) . value as * mut [ T ] as * mut T ;
1998+ let elems = ptr :: addr_of_mut! ( ( * ptr) . value) as * mut T ;
19951999
19962000 let mut guard = Guard { mem : NonNull :: new_unchecked ( mem) , elems, layout, n_elems : 0 } ;
19972001
@@ -2097,7 +2101,8 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Rc<T, A> {
20972101 self . inner ( ) . dec_weak ( ) ;
20982102
20992103 if self . inner ( ) . weak ( ) == 0 {
2100- self . alloc . deallocate ( self . ptr . cast ( ) , Layout :: for_value ( self . ptr . as_ref ( ) ) ) ;
2104+ self . alloc
2105+ . deallocate ( self . ptr . cast ( ) , Layout :: for_value_raw ( self . ptr . as_ptr ( ) ) ) ;
21012106 }
21022107 }
21032108 }
@@ -2525,7 +2530,7 @@ impl<T, A: Allocator> From<Vec<T, A>> for Rc<[T], A> {
25252530 let ( vec_ptr, len, cap, alloc) = v. into_raw_parts_with_alloc ( ) ;
25262531
25272532 let rc_ptr = Self :: allocate_for_slice_in ( len, & alloc) ;
2528- ptr:: copy_nonoverlapping ( vec_ptr, & mut ( * rc_ptr) . value as * mut [ T ] as * mut T , len) ;
2533+ ptr:: copy_nonoverlapping ( vec_ptr, ptr :: addr_of_mut! ( ( * rc_ptr) . value) as * mut T , len) ;
25292534
25302535 // Create a `Vec<T, &A>` with length 0, to deallocate the buffer
25312536 // without dropping its contents or the allocator
@@ -3515,7 +3520,7 @@ unsafe impl<#[may_dangle] T> Drop for UniqueRc<T> {
35153520 self . ptr . as_ref ( ) . dec_weak ( ) ;
35163521
35173522 if self . ptr . as_ref ( ) . weak ( ) == 0 {
3518- Global . deallocate ( self . ptr . cast ( ) , Layout :: for_value ( self . ptr . as_ref ( ) ) ) ;
3523+ Global . deallocate ( self . ptr . cast ( ) , Layout :: for_value_raw ( self . ptr . as_ptr ( ) ) ) ;
35193524 }
35203525 }
35213526 }
0 commit comments