Skip to content

Commit a875f77

Browse files
committed
alloc: simplify Default for Box<CStr> and Rc<CStr>
1 parent aa53782 commit a875f77

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

library/alloc/src/ffi/c_str.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff 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")]
980978
impl 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

0 commit comments

Comments
 (0)