Skip to content

Commit 0476fc4

Browse files
authored
Rollup merge of rust-lang#127433 - dtolnay:conststrlen, r=workingjubilee
Stabilize const_cstr_from_ptr (CStr::from_ptr, CStr::count_bytes) Completed the pair of FCPs rust-lang#113219 (comment) + rust-lang#114441 (comment). `CStr::from_ptr` is covered by just the first FCP on its own. `CStr::count_bytes` requires the approval of both FCPs. The second paragraph of the first link and the last paragraph of the second link explain the relationship between the two FCPs. As both have been approved, we can proceed with stabilizing `const` on both of these already-stable functions.
2 parents f66bd5f + 949f0d6 commit 0476fc4

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

core/src/ffi/c_str.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,6 @@ impl CStr {
263263
/// ```
264264
///
265265
/// ```
266-
/// #![feature(const_cstr_from_ptr)]
267-
///
268266
/// use std::ffi::{c_char, CStr};
269267
///
270268
/// const HELLO_PTR: *const c_char = {
@@ -280,7 +278,7 @@ impl CStr {
280278
#[inline] // inline is necessary for codegen to see strlen.
281279
#[must_use]
282280
#[stable(feature = "rust1", since = "1.0.0")]
283-
#[rustc_const_unstable(feature = "const_cstr_from_ptr", issue = "113219")]
281+
#[rustc_const_stable(feature = "const_cstr_from_ptr", since = "CURRENT_RUSTC_VERSION")]
284282
pub const unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr {
285283
// SAFETY: The caller has provided a pointer that points to a valid C
286284
// string with a NUL terminator less than `isize::MAX` from `ptr`.
@@ -542,7 +540,7 @@ impl CStr {
542540
#[must_use]
543541
#[doc(alias("len", "strlen"))]
544542
#[stable(feature = "cstr_count_bytes", since = "1.79.0")]
545-
#[rustc_const_unstable(feature = "const_cstr_from_ptr", issue = "113219")]
543+
#[rustc_const_stable(feature = "const_cstr_from_ptr", since = "CURRENT_RUSTC_VERSION")]
546544
pub const fn count_bytes(&self) -> usize {
547545
self.inner.len() - 1
548546
}
@@ -742,6 +740,9 @@ impl AsRef<CStr> for CStr {
742740
/// The pointer must point to a valid buffer that contains a NUL terminator. The NUL must be
743741
/// located within `isize::MAX` from `ptr`.
744742
#[inline]
743+
#[unstable(feature = "cstr_internals", issue = "none")]
744+
#[rustc_const_stable(feature = "const_cstr_from_ptr", since = "CURRENT_RUSTC_VERSION")]
745+
#[rustc_allow_const_fn_unstable(const_eval_select)]
745746
const unsafe fn const_strlen(ptr: *const c_char) -> usize {
746747
const fn strlen_ct(s: *const c_char) -> usize {
747748
let mut len = 0;

0 commit comments

Comments
 (0)