-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Stabilize const_cstr_methods
#107624
Stabilize const_cstr_methods
#107624
Conversation
r? @thomcc (rustbot has picked a reviewer for you, use r? to override) |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
The Miri subtree was changed cc @rust-lang/miri |
r? libs-api @rustbot label -T-libs |
Failed to set assignee to
|
f8199b9
to
3665612
Compare
#107429 merged, so this is no longer blocked. It needs the wg-const-eval signoff, but should otherwise be good |
30aa5b5
to
500eb06
Compare
☔ The latest upstream changes (presumably #108538) made this pull request unmergeable. Please resolve the merge conflicts. |
500eb06
to
6c42693
Compare
@rust-lang/libs-api: This PR stabilizes the impl CStr {
pub const fn from_bytes_with_nul(bytes: &[u8]) -> Result<&Self, FromBytesWithNulError>
pub const fn to_bytes(&self) -> &[u8]
pub const fn to_bytes_with_nul(&self) -> &[u8]
pub const fn to_str(&self) -> Result<&str, str::Utf8Error>
} Not all of these have a current implementation that is 100% on track for stabilization; for example the following, which uses https://doc.rust-lang.org/1.67.0/std/primitive.slice.html#method.get_unchecked, which doesn't even have a tracking issue but relies on being able to call trait methods inside const: However, I am confident that all of the functions for which const is being stabilized here could be reimplemented in a lower-level way using raw pointers, if necessary, to not call any trait methods. |
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! See this document for info about what commands tagged team members can give me. |
I believe the plan is still to make cc @rust-lang/wg-const-eval |
FCP needs one more check still @rust-lang/libs-api |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
SGTM. One concern I have about "assuming |
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. |
I believe The rust implementation of To summarize the possibilities:
So worst case, |
@dtolnay would you be able to merge this before the beta branch next week? |
@bors r+ |
…lnay Stabilize `const_cstr_methods` This PR seeks to stabilize `const_cstr_methods`. Fixes most of rust-lang#101719 ## New const stable API ```rust impl CStr { // depends: memchr pub const fn from_bytes_with_nul(bytes: &[u8]) -> Result<&Self, FromBytesWithNulError> {...} // depends: const_slice_index pub const fn to_bytes(&self) -> &[u8] {} // depends: pointer casts pub const fn to_bytes_with_nul(&self) -> &[u8] {} // depends: str::from_utf8 pub const fn to_str(&self) -> Result<&str, str::Utf8Error> {} } ``` I don't think any of these methods will have any issue when `CStr` becomes a thin pointer as long as `memchr` is const (which also allows for const `strlen`) . ## Notes - `from_bytes_until_nul` relies on `const_slice_index`, which relies on `const_trait_impls`, and generally this should be avoided. After talking with Oli, it should be OK in this case because we could replace the ranges with pointer tricks if needed (worst case being those feature gates disappear). rust-lang#107624 (comment) - Making `from_ptr` const is deferred because it depends on `const_eval_select`. I have moved this under the new flag `const_cstr_from_ptr` rust-lang#107624 (comment) cc `@oli-obk` I think you're the const expert `@rustbot` modify labels: +T-libs-api +needs-fcp
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#107624 (Stabilize `const_cstr_methods`) - rust-lang#111403 (suggest `slice::swap` for `mem::swap(&mut x[0], &mut x[1])` borrowck error) - rust-lang#113071 (Account for late-bound vars from parent arg-position impl trait) - rust-lang#113165 (Encode item bounds for `DefKind::ImplTraitPlaceholder`) - rust-lang#113171 (Properly implement variances_of for RPITIT GAT) - rust-lang#113177 (Use structured suggestion when telling user about `for<'a>`) r? `@ghost` `@rustbot` modify labels: rollup
Stabilize `const_cstr_methods` This PR seeks to stabilize `const_cstr_methods`. Fixes most of #101719 ## New const stable API ```rust impl CStr { // depends: memchr pub const fn from_bytes_with_nul(bytes: &[u8]) -> Result<&Self, FromBytesWithNulError> {...} // depends: const_slice_index pub const fn to_bytes(&self) -> &[u8] {} // depends: pointer casts pub const fn to_bytes_with_nul(&self) -> &[u8] {} // depends: str::from_utf8 pub const fn to_str(&self) -> Result<&str, str::Utf8Error> {} } ``` I don't think any of these methods will have any issue when `CStr` becomes a thin pointer as long as `memchr` is const (which also allows for const `strlen`) . ## Notes - `from_bytes_until_nul` relies on `const_slice_index`, which relies on `const_trait_impls`, and generally this should be avoided. After talking with Oli, it should be OK in this case because we could replace the ranges with pointer tricks if needed (worst case being those feature gates disappear). rust-lang/rust#107624 (comment) - Making `from_ptr` const is deferred because it depends on `const_eval_select`. I have moved this under the new flag `const_cstr_from_ptr` rust-lang/rust#107624 (comment) cc ``@oli-obk`` I think you're the const expert ``@rustbot`` modify labels: +T-libs-api +needs-fcp
This PR seeks to stabilize
const_cstr_methods
. Fixes most of #101719New const stable API
I don't think any of these methods will have any issue when
CStr
becomes a thin pointer as long asmemchr
is const (which also allows for conststrlen
) .Notes
from_bytes_until_nul
relies onconst_slice_index
, which relies onconst_trait_impls
, and generally this should be avoided. After talking with Oli, it should be OK in this case because we could replace the ranges with pointer tricks if needed (worst case being those feature gates disappear). Stabilizeconst_cstr_methods
#107624 (comment)from_ptr
const is deferred because it depends onconst_eval_select
. I have moved this under the new flagconst_cstr_from_ptr
Stabilizeconst_cstr_methods
#107624 (comment)cc @oli-obk I think you're the const expert
@rustbot modify labels: +T-libs-api +needs-fcp