File tree Expand file tree Collapse file tree 2 files changed +3
-8
lines changed Expand file tree Collapse file tree 2 files changed +3
-8
lines changed Original file line number Diff line number Diff line change @@ -970,17 +970,14 @@ impl Default for Rc<CStr> {
970970 /// This may or may not share an allocation with other Rcs on the same thread.
971971 #[ inline]
972972 fn default ( ) -> Self {
973- let rc = Rc :: < [ u8 ] > :: from ( * b"\0 " ) ;
974- // `[u8]` has the same layout as `CStr`, and it is `NUL` terminated.
975- unsafe { Rc :: from_raw ( Rc :: into_raw ( rc) as * const CStr ) }
973+ Rc :: from ( c"" )
976974 }
977975}
978976
979977#[ stable( feature = "default_box_extra" , since = "1.17.0" ) ]
980978impl Default for Box < CStr > {
981979 fn default ( ) -> Box < CStr > {
982- let boxed: Box < [ u8 ] > = Box :: from ( [ 0 ] ) ;
983- unsafe { Box :: from_raw ( Box :: into_raw ( boxed) as * mut CStr ) }
980+ Box :: from ( c"" )
984981 }
985982}
986983
Original file line number Diff line number Diff line change @@ -179,9 +179,7 @@ impl fmt::Debug for CStr {
179179impl Default for & CStr {
180180 #[ inline]
181181 fn default ( ) -> Self {
182- const SLICE : & [ c_char ] = & [ 0 ] ;
183- // SAFETY: `SLICE` is indeed pointing to a valid nul-terminated string.
184- unsafe { CStr :: from_ptr ( SLICE . as_ptr ( ) ) }
182+ c""
185183 }
186184}
187185
You can’t perform that action at this time.
0 commit comments