File tree 2 files changed +13
-1
lines changed
2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -1040,7 +1040,8 @@ impl CStr {
1040
1040
/// ```
1041
1041
#[ inline]
1042
1042
#[ 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 {
1044
1045
& * ( bytes as * const [ u8 ] as * const CStr )
1045
1046
}
1046
1047
@@ -1471,4 +1472,13 @@ mod tests {
1471
1472
assert_eq ! ( & * rc2, cstr) ;
1472
1473
assert_eq ! ( & * arc2, cstr) ;
1473
1474
}
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
+ }
1474
1484
}
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) ]
257
+ #![ feature( const_cstr_unchecked) ]
256
258
#![ feature( core_intrinsics) ]
257
259
#![ feature( dropck_eyepatch) ]
258
260
#![ feature( exact_size_is_empty) ]
You can’t perform that action at this time.
0 commit comments