Rollup merge of #155564 - tshakalekholoane:tshaka/const_default/cstr, r=jhpratt

Implement const Default for &CStr

Implements `const Default` for `&CStr`.

Tracking issue: rust-lang/rust#143894.
This commit is contained in:
Jacob Pratt
2026-04-21 02:20:27 -04:00
committed by GitHub
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