-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking Issue for const_cstr_from_ptr
#113219
Comments
Tracking issue rust-lang#101719 was for `const_cstr_methods`, rust-lang#113219 is a new issue specific for `const_cstr_from_ptr`.
…ing-issue, r=ChrisDenton Update the tracking issue for `const_cstr_from_ptr` Tracking issue rust-lang#101719 was for `const_cstr_methods`, rust-lang#113219 is a new issue specific for `const_cstr_from_ptr`. (I believe rust-lang#101719 could also be closed) `@rustbot` label +T-libs-api +A-docs
…ing-issue, r=ChrisDenton Update the tracking issue for `const_cstr_from_ptr` Tracking issue rust-lang#101719 was for `const_cstr_methods`, rust-lang#113219 is a new issue specific for `const_cstr_from_ptr`. (I believe rust-lang#101719 could also be closed) ``@rustbot`` label +T-libs-api +A-docs
…ing-issue, r=ChrisDenton Update the tracking issue for `const_cstr_from_ptr` Tracking issue rust-lang#101719 was for `const_cstr_methods`, rust-lang#113219 is a new issue specific for `const_cstr_from_ptr`. (I believe rust-lang#101719 could also be closed) ```@rustbot``` label +T-libs-api +A-docs
I gated |
This is feature gated under `cstr_count_bytes` and provides a more straightforward way to access the length of a `CStr` Link: rust-lang#113219
This comment was marked as resolved.
This comment was marked as resolved.
I infer that this is rust-lang/rfcs#3352. According to #107624 (comment), T-libs-api should not look into stabilizing the APIs tracked by this tracking issue until some clarity has been reached by T-lang on that RFC. I have added a link to that RFC to the checklist in this issue. |
That all sounds correct, thanks for the updates |
Why is rust-lang/rfcs#3352 listed as a blocker here? Using const_eval_select in stable const fn is fine, and in fact we already do that, e.g. |
Oh I see, this probably goes back to this discussion. So far we're only using const_eval_select to control assertions, this needs it to provide a const-time implementation for But still, I don't think that requires the RFC -- as Oli said, all that requires is to commit to is that we'll have some way of calling |
@rust-lang/libs-api, @rust-lang/lang: I propose stabilizing impl CStr {
pub const unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr;
} Relatedly, I propose moving the impl CStr {
#[unstable]
pub const fn count_bytes(&self) -> usize;
} The rust/library/core/src/ffi/c_str.rs Lines 733 to 757 in d36bdd1
For previous discussion of whether this is okay to stabilize as Note that this feature would be the first time we stabilize a usage of rust/library/core/src/ffi/c_str.rs Lines 407 to 442 in d36bdd1
|
Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
Given that const unsafe fn count_bytes(p: *const u8) -> usize {
let mut i = 0;
loop {
if *p.add(i) == 0 { return i }
i += 1;
}
} compiles on stable, I don't see any lang concerns here. Totally happy leaving this up to libs-api. @rfcbot reviewed |
…s, r=dtolnay Stabilize `cstr_count_bytes` Newly stable API: ```rust impl CStr { pub fn count_bytes(&self) -> usize; } ``` Const stabilization has not yet been decided, so that will continue to be gated under <rust-lang#113219>. FCP finished at rust-lang#114441 (comment). Fixes: <rust-lang#114441>
Rollup merge of rust-lang#123661 - tgross35:stabilize-cstr_count_bytes, r=dtolnay Stabilize `cstr_count_bytes` Newly stable API: ```rust impl CStr { pub fn count_bytes(&self) -> usize; } ``` Const stabilization has not yet been decided, so that will continue to be gated under <rust-lang#113219>. FCP finished at rust-lang#114441 (comment). Fixes: <rust-lang#114441>
@joshtriplett @m-ou-se @nikomatsakis @pnkfelix @tmandry reminder that there's a checkbox here waiting for you. :) |
@rfcbot reviewed |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
@rustbot labels -I-lang-nominated We discussed this in the lang call today. Everyone felt comfortable with it, and it's now in FCP. |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
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.
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.
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.
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.
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.
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.
Since the libs and lang teams completed an FCP to allow for const `strlen` ([1]), currently implemented with `const_eval_select`, there is no longer any reason to avoid this specific function or use it only in const. Rename it to reflect this status change. [1]: rust-lang#113219 (comment)
…olnay Rename the internal `const_strlen` to just `strlen` Since the libs and lang teams completed an FCP to allow for const `strlen` ([1]), currently implemented with `const_eval_select`, there is no longer any reason to avoid this specific function or use it only in const. Rename it to reflect this status change. [1]: rust-lang#113219 (comment)
Rollup merge of rust-lang#127660 - tgross35:const_strlen-rename, r=dtolnay Rename the internal `const_strlen` to just `strlen` Since the libs and lang teams completed an FCP to allow for const `strlen` ([1]), currently implemented with `const_eval_select`, there is no longer any reason to avoid this specific function or use it only in const. Rename it to reflect this status change. [1]: rust-lang#113219 (comment)
Feature gate:
#![feature(const_cstr_from_ptr)]
This is a tracking issue for using
CStr::from_ptr()
in a const context.This method was previously gated under
const_cstr_methods
, but was split off after discussion in #107624 (review).Public API
Steps / History
Blocked on Relax const-eval restrictions rfcs#3352 (?)Unresolved Questions
Making this const currently depends on
const_eval_select
, which unstable. Ifconst_eval_select
becomes internally usable, we will be able to stabilize this.The other currently available option is to always use a const
strlen
, but this would come with a performance hit.Alternatively, whenever
CStr
becomes a thin pointer this can be const stabilized since it will have no internal operations.The text was updated successfully, but these errors were encountered: