@@ -38,6 +38,12 @@ pub struct RefCounts {
3838 pub strong : UnsafeCell < usize > ,
3939}
4040
41+ impl RefCounts {
42+ const fn new ( strong_cont : usize ) -> Self {
43+ Self { weak : UnsafeCell :: new ( 1 ) , strong : UnsafeCell :: new ( strong_cont) }
44+ }
45+ }
46+
4147struct RcLayout {
4248 allocation_layout : Layout ,
4349 allocation_offset_bytes : usize ,
@@ -74,12 +80,12 @@ impl RcLayout {
7480 }
7581}
7682
77- trait RcLayoutExt < T > {
83+ trait RcLayoutExt {
7884 const RC_LAYOUT : RcLayout ;
7985}
8086
81- impl < T > RcLayoutExt < T > for T {
82- const RC_LAYOUT : RcLayout = match RcLayout :: of :: < T > ( ) {
87+ impl < T > RcLayoutExt for T {
88+ const RC_LAYOUT : RcLayout = match RcLayout :: of :: < Self > ( ) {
8389 Ok ( rc_layout) => rc_layout,
8490 Err ( _) => panic ! ( "layout size is too large" ) ,
8591 } ;
@@ -111,9 +117,7 @@ unsafe fn write_rc_allocation<const STRONG_COUNT: usize>(
111117) -> NonNull < ( ) > {
112118 let allocation_ptr = ptr. cast :: < ( ) > ( ) ;
113119 let value_ptr = unsafe { allocation_ptr. byte_add ( rc_layout. allocation_offset_bytes ) } ;
114-
115- let ref_counts =
116- const { RefCounts { weak : UnsafeCell :: new ( 1 ) , strong : UnsafeCell :: new ( STRONG_COUNT ) } } ;
120+ let ref_counts = const { RefCounts :: new ( STRONG_COUNT ) } ;
117121
118122 unsafe { ref_counts_ptr_from_value_ptr ( value_ptr) . write ( ref_counts) } ;
119123
@@ -271,7 +275,7 @@ impl<T, A> RawWeak<T, A>
271275where
272276 T : ?Sized ,
273277{
274- pub unsafe fn from_raw_parts ( ptr : NonNull < T > , alloc : A ) -> Self {
278+ pub const unsafe fn from_raw_parts ( ptr : NonNull < T > , alloc : A ) -> Self {
275279 Self { ptr, alloc }
276280 }
277281
@@ -295,7 +299,7 @@ where
295299 U : ?Sized ,
296300 F : FnOnce ( NonNull < T > ) -> NonNull < U > ,
297301 {
298- RawWeak { ptr : f ( self . ptr ) , alloc : self . alloc }
302+ unsafe { RawWeak :: from_raw_parts ( f ( self . ptr ) , self . alloc ) }
299303 }
300304
301305 pub unsafe fn cast < U > ( self ) -> RawWeak < U , A > {
@@ -453,9 +457,11 @@ where
453457
454458impl < T , A > RawWeak < T , A > {
455459 pub const fn new_dangling_in ( alloc : A ) -> Self {
456- Self {
457- ptr : unsafe { NonNull :: new_unchecked ( ptr:: without_provenance_mut :: < T > ( usize:: MAX ) ) } ,
458- alloc,
460+ unsafe {
461+ Self :: from_raw_parts (
462+ NonNull :: new_unchecked ( ptr:: without_provenance_mut :: < T > ( usize:: MAX ) ) ,
463+ alloc,
464+ )
459465 }
460466 }
461467
@@ -1648,6 +1654,13 @@ where
16481654{
16491655}
16501656
1657+ impl < T , U > DispatchFromDyn < RawUniqueRc < U , Global > > for RawUniqueRc < T , Global >
1658+ where
1659+ T : ?Sized + Unsize < U > ,
1660+ U : ?Sized ,
1661+ {
1662+ }
1663+
16511664impl < T , A > Debug for RawUniqueRc < T , A >
16521665where
16531666 T : Debug + ?Sized ,
0 commit comments