Implement const Default for &CStr

This commit is contained in:
Tshaka Lekholoane
2026-04-20 17:40:30 +02:00
parent d12e1e12ae
commit 339a2f0ba0
2 changed files with 8 additions and 1 deletions
+2 -1
View File
@@ -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""
+6
View File
@@ -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