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