@@ -303,18 +303,16 @@ impl<T> Rc<T> {
303303 /// ```
304304 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
305305 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+ } ) ) ,
318316 }
319317 }
320318
@@ -418,7 +416,7 @@ impl<T> Rc<T> {
418416
419417 let ptr = ( ptr as * const u8 ) . offset ( -offset_of ! ( RcBox <T >, value) ) ;
420418 Rc {
421- ptr : Shared :: new ( ptr as * mut u8 as * mut _ )
419+ ptr : Shared :: new_unchecked ( ptr as * mut u8 as * mut _ )
422420 }
423421 }
424422}
@@ -443,7 +441,7 @@ impl Rc<str> {
443441 // Combine the allocation address and the string length into a fat pointer to `RcBox`.
444442 let rcbox_ptr: * mut RcBox < str > = mem:: transmute ( [ ptr as usize , value. len ( ) ] ) ;
445443 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) }
447445 }
448446 }
449447}
@@ -476,7 +474,7 @@ impl<T> Rc<[T]> {
476474 // Free the original allocation without freeing its (moved) contents.
477475 box_free ( Box :: into_raw ( value) ) ;
478476
479- Rc { ptr : Shared :: new ( ptr as * mut _ ) }
477+ Rc { ptr : Shared :: new_unchecked ( ptr as * mut _ ) }
480478 }
481479 }
482480}
@@ -1016,7 +1014,7 @@ impl<T> Weak<T> {
10161014 pub fn new ( ) -> Weak < T > {
10171015 unsafe {
10181016 Weak {
1019- ptr : Shared :: new ( Box :: into_raw ( box RcBox {
1017+ ptr : Shared :: from ( Box :: into_unique ( box RcBox {
10201018 strong : Cell :: new ( 0 ) ,
10211019 weak : Cell :: new ( 1 ) ,
10221020 value : uninitialized ( ) ,
0 commit comments