about summary refs log tree commit diff
path: root/src/libstd/ffi
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd/ffi')
-rw-r--r--src/libstd/ffi/c_str.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs
index 63dd12f782f..dfec13cd2ec 100644
--- a/src/libstd/ffi/c_str.rs
+++ b/src/libstd/ffi/c_str.rs
@@ -1040,7 +1040,8 @@ impl CStr {
     /// ```
     #[inline]
     #[stable(feature = "cstr_from_bytes", since = "1.10.0")]
-    pub unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr {
+    #[rustc_const_unstable(feature = "const_cstr_unchecked")]
+    pub const unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr {
         &*(bytes as *const [u8] as *const CStr)
     }
 
@@ -1471,4 +1472,13 @@ mod tests {
         assert_eq!(&*rc2, cstr);
         assert_eq!(&*arc2, cstr);
     }
+
+    #[test]
+    fn cstr_const_constructor() {
+        const CSTR: &'static CStr = unsafe {
+            CStr::from_bytes_with_nul_unchecked(b"Hello, world!\0")
+        };
+
+        assert_eq!(CSTR.to_str().unwrap(), "Hello, world!");
+    }
 }