File tree 2 files changed +12
-1
lines changed
2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -1090,7 +1090,8 @@ impl CStr {
1090
1090
/// ```
1091
1091
#[ inline]
1092
1092
#[ stable( feature = "cstr_from_bytes" , since = "1.10.0" ) ]
1093
- pub unsafe fn from_bytes_with_nul_unchecked ( bytes : & [ u8 ] ) -> & CStr {
1093
+ #[ rustc_const_unstable( feature = "const_cstr_unchecked" ) ]
1094
+ pub const unsafe fn from_bytes_with_nul_unchecked ( bytes : & [ u8 ] ) -> & CStr {
1094
1095
& * ( bytes as * const [ u8 ] as * const CStr )
1095
1096
}
1096
1097
@@ -1521,4 +1522,13 @@ mod tests {
1521
1522
assert_eq ! ( & * rc2, cstr) ;
1522
1523
assert_eq ! ( & * arc2, cstr) ;
1523
1524
}
1525
+
1526
+ #[ test]
1527
+ fn cstr_const_constructor ( ) {
1528
+ const CSTR : & ' static CStr = unsafe {
1529
+ CStr :: from_bytes_with_nul_unchecked ( b"Hello, world!\0 " )
1530
+ } ;
1531
+
1532
+ assert_eq ! ( CSTR . to_str( ) . unwrap( ) , "Hello, world!" ) ;
1533
+ }
1524
1534
}
Original file line number Diff line number Diff line change 253
253
#![ feature( min_const_fn) ]
254
254
#![ feature( const_int_ops) ]
255
255
#![ feature( const_ip) ]
256
+ #![ feature( const_raw_ptr_deref) ]
256
257
#![ feature( core_intrinsics) ]
257
258
#![ feature( dropck_eyepatch) ]
258
259
#![ feature( duration_as_u128) ]
You can’t perform that action at this time.
0 commit comments