@@ -303,18 +303,16 @@ impl<T> Rc<T> {
303
303
/// ```
304
304
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
305
305
pub fn new ( value : T ) -> Rc < T > {
306
- unsafe {
307
- Rc {
308
- // there is an implicit weak pointer owned by all the strong
309
- // pointers, which ensures that the weak destructor never frees
310
- // the allocation while the strong destructor is running, even
311
- // if the weak pointer is stored inside the strong one.
312
- ptr : Shared :: new ( Box :: into_raw ( box RcBox {
313
- strong : Cell :: new ( 1 ) ,
314
- weak : Cell :: new ( 1 ) ,
315
- value : value,
316
- } ) ) ,
317
- }
306
+ Rc {
307
+ // there is an implicit weak pointer owned by all the strong
308
+ // pointers, which ensures that the weak destructor never frees
309
+ // the allocation while the strong destructor is running, even
310
+ // if the weak pointer is stored inside the strong one.
311
+ ptr : Shared :: from ( Box :: into_unique ( box RcBox {
312
+ strong : Cell :: new ( 1 ) ,
313
+ weak : Cell :: new ( 1 ) ,
314
+ value : value,
315
+ } ) ) ,
318
316
}
319
317
}
320
318
@@ -418,7 +416,7 @@ impl<T> Rc<T> {
418
416
419
417
let ptr = ( ptr as * const u8 ) . offset ( -offset_of ! ( RcBox <T >, value) ) ;
420
418
Rc {
421
- ptr : Shared :: new ( ptr as * mut u8 as * mut _ )
419
+ ptr : Shared :: new_unchecked ( ptr as * mut u8 as * mut _ )
422
420
}
423
421
}
424
422
}
@@ -443,7 +441,7 @@ impl Rc<str> {
443
441
// Combine the allocation address and the string length into a fat pointer to `RcBox`.
444
442
let rcbox_ptr: * mut RcBox < str > = mem:: transmute ( [ ptr as usize , value. len ( ) ] ) ;
445
443
assert ! ( aligned_len * size_of:: <usize >( ) == size_of_val( & * rcbox_ptr) ) ;
446
- Rc { ptr : Shared :: new ( rcbox_ptr) }
444
+ Rc { ptr : Shared :: new_unchecked ( rcbox_ptr) }
447
445
}
448
446
}
449
447
}
@@ -476,7 +474,7 @@ impl<T> Rc<[T]> {
476
474
// Free the original allocation without freeing its (moved) contents.
477
475
box_free ( Box :: into_raw ( value) ) ;
478
476
479
- Rc { ptr : Shared :: new ( ptr as * mut _ ) }
477
+ Rc { ptr : Shared :: new_unchecked ( ptr as * mut _ ) }
480
478
}
481
479
}
482
480
}
@@ -1016,7 +1014,7 @@ impl<T> Weak<T> {
1016
1014
pub fn new ( ) -> Weak < T > {
1017
1015
unsafe {
1018
1016
Weak {
1019
- ptr : Shared :: new ( Box :: into_raw ( box RcBox {
1017
+ ptr : Shared :: from ( Box :: into_unique ( box RcBox {
1020
1018
strong : Cell :: new ( 0 ) ,
1021
1019
weak : Cell :: new ( 1 ) ,
1022
1020
value : uninitialized ( ) ,
0 commit comments