@@ -1885,10 +1885,10 @@ impl<T: ?Sized> Rc<T> {
1885
1885
// Initialize the RcBox
1886
1886
let inner = mem_to_rcbox ( ptr. as_non_null_ptr ( ) . as_ptr ( ) ) ;
1887
1887
unsafe {
1888
- debug_assert_eq ! ( Layout :: for_value ( & * inner) , layout) ;
1888
+ debug_assert_eq ! ( Layout :: for_value_raw ( inner) , layout) ;
1889
1889
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 ) ) ;
1892
1892
}
1893
1893
1894
1894
Ok ( inner)
@@ -1902,7 +1902,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
1902
1902
// Allocate for the `RcBox<T>` using the given value.
1903
1903
unsafe {
1904
1904
Rc :: < T > :: allocate_for_layout (
1905
- Layout :: for_value ( & * ptr) ,
1905
+ Layout :: for_value_raw ( ptr) ,
1906
1906
|layout| alloc. allocate ( layout) ,
1907
1907
|mem| mem. with_metadata_of ( ptr as * const RcBox < T > ) ,
1908
1908
)
@@ -1918,7 +1918,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
1918
1918
// Copy value as bytes
1919
1919
ptr:: copy_nonoverlapping (
1920
1920
& * 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 ,
1922
1922
value_size,
1923
1923
) ;
1924
1924
@@ -1952,7 +1952,11 @@ impl<T> Rc<[T]> {
1952
1952
unsafe fn copy_from_slice ( v : & [ T ] ) -> Rc < [ T ] > {
1953
1953
unsafe {
1954
1954
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
+ ) ;
1956
1960
Self :: from_ptr ( ptr)
1957
1961
}
1958
1962
}
@@ -1987,10 +1991,10 @@ impl<T> Rc<[T]> {
1987
1991
let ptr = Self :: allocate_for_slice ( len) ;
1988
1992
1989
1993
let mem = ptr as * mut _ as * mut u8 ;
1990
- let layout = Layout :: for_value ( & * ptr) ;
1994
+ let layout = Layout :: for_value_raw ( ptr) ;
1991
1995
1992
1996
// 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 ;
1994
1998
1995
1999
let mut guard = Guard { mem : NonNull :: new_unchecked ( mem) , elems, layout, n_elems : 0 } ;
1996
2000
@@ -2096,7 +2100,8 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Rc<T, A> {
2096
2100
self . inner ( ) . dec_weak ( ) ;
2097
2101
2098
2102
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 ( ) ) ) ;
2100
2105
}
2101
2106
}
2102
2107
}
@@ -2524,7 +2529,7 @@ impl<T, A: Allocator> From<Vec<T, A>> for Rc<[T], A> {
2524
2529
let ( vec_ptr, len, cap, alloc) = v. into_raw_parts_with_alloc ( ) ;
2525
2530
2526
2531
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) ;
2528
2533
2529
2534
// Create a `Vec<T, &A>` with length 0, to deallocate the buffer
2530
2535
// without dropping its contents or the allocator
@@ -3514,7 +3519,7 @@ unsafe impl<#[may_dangle] T> Drop for UniqueRc<T> {
3514
3519
self . ptr . as_ref ( ) . dec_weak ( ) ;
3515
3520
3516
3521
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 ( ) ) ) ;
3518
3523
}
3519
3524
}
3520
3525
}
0 commit comments