@@ -1885,10 +1885,10 @@ impl<T: ?Sized> Rc<T> {
18851885 // Initialize the RcBox
18861886 let inner = mem_to_rcbox ( ptr. as_non_null_ptr ( ) . as_ptr ( ) ) ;
18871887 unsafe {
1888- debug_assert_eq ! ( Layout :: for_value ( & * inner) , layout) ;
1888+ debug_assert_eq ! ( Layout :: for_value_raw ( inner) , layout) ;
18891889
1890- ptr:: write ( & mut ( * inner) . strong , Cell :: new ( 1 ) ) ;
1891- ptr:: write ( & mut ( * inner) . weak , Cell :: new ( 1 ) ) ;
1890+ ptr:: addr_of_mut! ( ( * inner) . strong) . write ( Cell :: new ( 1 ) ) ;
1891+ ptr:: addr_of_mut! ( ( * inner) . weak) . write ( Cell :: new ( 1 ) ) ;
18921892 }
18931893
18941894 Ok ( inner)
@@ -1902,7 +1902,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
19021902 // Allocate for the `RcBox<T>` using the given value.
19031903 unsafe {
19041904 Rc :: < T > :: allocate_for_layout (
1905- Layout :: for_value ( & * ptr) ,
1905+ Layout :: for_value_raw ( ptr) ,
19061906 |layout| alloc. allocate ( layout) ,
19071907 |mem| mem. with_metadata_of ( ptr as * const RcBox < T > ) ,
19081908 )
@@ -1918,7 +1918,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
19181918 // Copy value as bytes
19191919 ptr:: copy_nonoverlapping (
19201920 & * src as * const T as * const u8 ,
1921- & mut ( * ptr) . value as * mut _ as * mut u8 ,
1921+ ptr :: addr_of_mut! ( ( * ptr) . value) as * mut u8 ,
19221922 value_size,
19231923 ) ;
19241924
@@ -1952,7 +1952,11 @@ impl<T> Rc<[T]> {
19521952 unsafe fn copy_from_slice ( v : & [ T ] ) -> Rc < [ T ] > {
19531953 unsafe {
19541954 let ptr = Self :: allocate_for_slice ( v. len ( ) ) ;
1955- ptr:: copy_nonoverlapping ( v. as_ptr ( ) , & mut ( * ptr) . value as * mut [ T ] as * mut T , v. len ( ) ) ;
1955+ ptr:: copy_nonoverlapping (
1956+ v. as_ptr ( ) ,
1957+ ptr:: addr_of_mut!( ( * ptr) . value) as * mut T ,
1958+ v. len ( ) ,
1959+ ) ;
19561960 Self :: from_ptr ( ptr)
19571961 }
19581962 }
@@ -1987,10 +1991,10 @@ impl<T> Rc<[T]> {
19871991 let ptr = Self :: allocate_for_slice ( len) ;
19881992
19891993 let mem = ptr as * mut _ as * mut u8 ;
1990- let layout = Layout :: for_value ( & * ptr) ;
1994+ let layout = Layout :: for_value_raw ( ptr) ;
19911995
19921996 // Pointer to first element
1993- let elems = & mut ( * ptr) . value as * mut [ T ] as * mut T ;
1997+ let elems = ptr :: addr_of_mut! ( ( * ptr) . value) as * mut T ;
19941998
19951999 let mut guard = Guard { mem : NonNull :: new_unchecked ( mem) , elems, layout, n_elems : 0 } ;
19962000
@@ -2096,7 +2100,8 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Rc<T, A> {
20962100 self . inner ( ) . dec_weak ( ) ;
20972101
20982102 if self . inner ( ) . weak ( ) == 0 {
2099- self . alloc . deallocate ( self . ptr . cast ( ) , Layout :: for_value ( self . ptr . as_ref ( ) ) ) ;
2103+ self . alloc
2104+ . deallocate ( self . ptr . cast ( ) , Layout :: for_value_raw ( self . ptr . as_ptr ( ) ) ) ;
21002105 }
21012106 }
21022107 }
@@ -2524,7 +2529,7 @@ impl<T, A: Allocator> From<Vec<T, A>> for Rc<[T], A> {
25242529 let ( vec_ptr, len, cap, alloc) = v. into_raw_parts_with_alloc ( ) ;
25252530
25262531 let rc_ptr = Self :: allocate_for_slice_in ( len, & alloc) ;
2527- ptr:: copy_nonoverlapping ( vec_ptr, & mut ( * rc_ptr) . value as * mut [ T ] as * mut T , len) ;
2532+ ptr:: copy_nonoverlapping ( vec_ptr, ptr :: addr_of_mut! ( ( * rc_ptr) . value) as * mut T , len) ;
25282533
25292534 // Create a `Vec<T, &A>` with length 0, to deallocate the buffer
25302535 // without dropping its contents or the allocator
@@ -3514,7 +3519,7 @@ unsafe impl<#[may_dangle] T> Drop for UniqueRc<T> {
35143519 self . ptr . as_ref ( ) . dec_weak ( ) ;
35153520
35163521 if self . ptr . as_ref ( ) . weak ( ) == 0 {
3517- Global . deallocate ( self . ptr . cast ( ) , Layout :: for_value ( self . ptr . as_ref ( ) ) ) ;
3522+ Global . deallocate ( self . ptr . cast ( ) , Layout :: for_value_raw ( self . ptr . as_ptr ( ) ) ) ;
35183523 }
35193524 }
35203525 }
0 commit comments