File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -1040,7 +1040,8 @@ impl CStr {
10401040 /// ```
10411041 #[ inline]
10421042 #[ stable( feature = "cstr_from_bytes" , since = "1.10.0" ) ]
1043- pub unsafe fn from_bytes_with_nul_unchecked ( bytes : & [ u8 ] ) -> & CStr {
1043+ #[ rustc_const_unstable( feature = "const_cstr_unchecked" ) ]
1044+ pub const unsafe fn from_bytes_with_nul_unchecked ( bytes : & [ u8 ] ) -> & CStr {
10441045 & * ( bytes as * const [ u8 ] as * const CStr )
10451046 }
10461047
@@ -1471,4 +1472,13 @@ mod tests {
14711472 assert_eq ! ( & * rc2, cstr) ;
14721473 assert_eq ! ( & * arc2, cstr) ;
14731474 }
1475+
1476+ #[ test]
1477+ fn cstr_const_constructor ( ) {
1478+ const CSTR : & ' static CStr = unsafe {
1479+ CStr :: from_bytes_with_nul_unchecked ( b"Hello, world!\0 " )
1480+ } ;
1481+
1482+ assert_eq ! ( CSTR . to_str( ) . unwrap( ) , "Hello, world!" ) ;
1483+ }
14741484}
Original file line number Diff line number Diff line change 253253#![ feature( min_const_fn) ]
254254#![ feature( const_int_ops) ]
255255#![ feature( const_ip) ]
256+ #![ feature( const_raw_ptr_deref) ]
257+ #![ feature( const_cstr_unchecked) ]
256258#![ feature( core_intrinsics) ]
257259#![ feature( dropck_eyepatch) ]
258260#![ feature( exact_size_is_empty) ]
You can’t perform that action at this time.
0 commit comments