File tree 1 file changed +4
-3
lines changed
1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -375,16 +375,17 @@ impl Rc<str> {
375
375
pub fn __from_str ( value : & str ) -> Rc < str > {
376
376
unsafe {
377
377
// Allocate enough space for `RcBox<str>`.
378
- let aligned_len = ( value. len ( ) + size_of :: < usize > ( ) - 1 ) / size_of :: < usize > ( ) ;
379
- let vec = RawVec :: < usize > :: with_capacity ( 2 + aligned_len) ;
378
+ let aligned_len = 2 + ( value. len ( ) + size_of :: < usize > ( ) - 1 ) / size_of :: < usize > ( ) ;
379
+ let vec = RawVec :: < usize > :: with_capacity ( aligned_len) ;
380
380
let ptr = vec. ptr ( ) ;
381
381
forget ( vec) ;
382
382
// Initialize fields of `RcBox<str>`.
383
383
* ptr. offset ( 0 ) = 1 ; // strong: Cell::new(1)
384
384
* ptr. offset ( 1 ) = 1 ; // weak: Cell::new(1)
385
385
ptr:: copy_nonoverlapping ( value. as_ptr ( ) , ptr. offset ( 2 ) as * mut u8 , value. len ( ) ) ;
386
386
// Combine the allocation address and the string length into a fat pointer to `RcBox`.
387
- let rcbox_ptr = mem:: transmute ( [ ptr as usize , value. len ( ) ] ) ;
387
+ let rcbox_ptr: * mut RcBox < str > = mem:: transmute ( [ ptr as usize , value. len ( ) ] ) ;
388
+ assert ! ( aligned_len * size_of:: <usize >( ) == size_of_val( & * rcbox_ptr) ) ;
388
389
Rc { ptr : Shared :: new ( rcbox_ptr) }
389
390
}
390
391
}
You can’t perform that action at this time.
0 commit comments