diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index e3a3aed4a794..97831c41dc0f 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -176,7 +176,8 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { } #[stable(feature = "cstr_default", since = "1.10.0")] -impl Default for &CStr { +#[rustc_const_unstable(feature = "const_default", issue = "143894")] +impl const Default for &CStr { #[inline] fn default() -> Self { c"" diff --git a/library/coretests/tests/ffi/cstr.rs b/library/coretests/tests/ffi/cstr.rs index 7d669cc1c3ff..0fb98036b267 100644 --- a/library/coretests/tests/ffi/cstr.rs +++ b/library/coretests/tests/ffi/cstr.rs @@ -1,5 +1,11 @@ use core::ffi::CStr; +#[test] +fn const_default() { + const S: &CStr = <_>::default(); + assert_eq!(S, c""); +} + #[test] fn compares_as_u8s() { let a: &CStr = c"Hello!"; // Starts with ascii