diff options
| author | bors <bors@rust-lang.org> | 2018-10-02 23:29:58 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-10-02 23:29:58 +0000 |
| commit | 4cf11765dc98536c6eedf33f2df7f72f6e161263 (patch) | |
| tree | 3b16725548b5703f39b05a0deb2bde6b36223246 /src/libstd | |
| parent | 2bd5993ca25e09b894e4fd6539a2fba64599eee2 (diff) | |
| parent | 00e4b27796dc9e533777c2cbf323df94c3427592 (diff) | |
| download | rust-4cf11765dc98536c6eedf33f2df7f72f6e161263.tar.gz rust-4cf11765dc98536c6eedf33f2df7f72f6e161263.zip | |
Auto merge of #54767 - pietroalbini:rollup, r=pietroalbini
Rollup of 10 pull requests Successful merges: - #54269 (#53840: Consolidate pattern check errors) - #54458 (Allow both explicit and elided lifetimes in the same impl header) - #54603 (Add `crate::` to trait suggestions in Rust 2018.) - #54648 (Update Cargo's submodule) - #54680 (make run-pass tests with empty main just compile-pass tests) - #54687 (Use impl_header_lifetime_elision in libcore) - #54699 (Re-export `getopts` so custom drivers can reference it.) - #54702 (do not promote comparing function pointers) - #54728 (Renumber `proc_macro` tracking issues) - #54745 (make `CStr::from_bytes_with_nul_unchecked()` a const fn) Failed merges: r? @ghost
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/ffi/c_str.rs | 12 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 2 |
2 files changed, 13 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!"); + } } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 7ae4f2de4c3..afe0b67e330 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -253,6 +253,8 @@ #![feature(min_const_fn)] #![feature(const_int_ops)] #![feature(const_ip)] +#![feature(const_raw_ptr_deref)] +#![feature(const_cstr_unchecked)] #![feature(core_intrinsics)] #![feature(dropck_eyepatch)] #![feature(exact_size_is_empty)] |
