Skip to content

Tracking Issue for const_vec_string_slice #129041

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
2 of 3 tasks
GrigorenkoPV opened this issue Aug 13, 2024 · 9 comments
Open
2 of 3 tasks

Tracking Issue for const_vec_string_slice #129041

GrigorenkoPV opened this issue Aug 13, 2024 · 9 comments
Labels
A-str Area: str and String C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Milestone

Comments

@GrigorenkoPV
Copy link
Contributor

GrigorenkoPV commented Aug 13, 2024

Feature gate: #![feature(const_vec_string_slice)]

This is a tracking issue for making a bunch of String and Vec methods const.

Public API

The following methods are now const:

impl String {
    pub const fn into_bytes(self) -> Vec<u8>;
    pub const fn as_str(&self) -> &str;
    pub const fn capacity(&self) -> usize;
    pub const fn as_bytes(&self) -> &[u8];
    pub const fn len(&self) -> usize;
    pub const fn is_empty(&self) -> bool;
}

impl Vec<T> {
    pub const fn capacity(&self) -> usize;
    pub const fn as_slice(&self) -> &[T];
    pub const fn as_ptr(&self) -> *const T;
    pub const fn len(&self) -> usize;
    pub const fn is_empty(&self) -> bool;
}

A few additional methods are under this feature gate but were not included in the FCP at #129041 (comment); they got FCP'd in #137319 (comment):

impl String {
    pub const fn as_mut_str(&mut self) -> &mut str;
    pub const unsafe fn as_mut_vec(&mut self) -> &mut Vec<u8>;
}

impl Vec<T> {
    pub const fn as_mut_slice(&mut self) -> &mut [T];
    pub const fn as_mut_ptr(&mut self) -> *mut T;
}

Steps / History

Unresolved Questions

  • None yet.

@rustbot label A-str

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

@GrigorenkoPV GrigorenkoPV added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Aug 13, 2024
@rustbot rustbot added the A-str Area: str and String label Aug 13, 2024
@Esper89
Copy link

Esper89 commented Aug 13, 2024

This would be very useful for const fns that sometimes need to handle runtime data too, such as a const fn method that needs to use a Cow<'static, [T]> field.

For example:

struct Foo(Cow<'static, [u32]>);

impl Foo {
    // Initialize with heap-allocated data at runtime.
    fn heap(data: Vec<u32>) -> Self {
        Foo(Cow::Owned(data))
    }

    // Initialize with static data at compile-time.
    const fn static(data: &'static [u32]) -> Self {
        Foo(Cow::Borrowed(data))
    }

    // Access the data, possibly at compile-time, possibly at runtime.
    const fn data(&self) -> &[u32] {
        match self.0 {
            Cow::Borrowed(slice) => slice,
            Cow::Owned(vec) => vec.as_slice(),
        }
    }
}

mammothbane added a commit to mammothbane/rust that referenced this issue Sep 5, 2024
This change `const`-qualifies many methods on Vec and String, notably
`as_slice`, `as_str`, `len`. These changes are made behind the unstable
feature flag `const_vec_string_slice` with the following tracking issue:

rust-lang#129041
mammothbane added a commit to mammothbane/rust that referenced this issue Sep 19, 2024
This change `const`-qualifies many methods on Vec and String, notably
`as_slice`, `as_str`, `len`. These changes are made behind the unstable
feature flag `const_vec_string_slice` with the following tracking issue:

rust-lang#129041
mammothbane added a commit to mammothbane/rust that referenced this issue Sep 19, 2024
This change `const`-qualifies many methods on Vec and String, notably
`as_slice`, `as_str`, `len`. These changes are made behind the unstable
feature flag `const_vec_string_slice` with the following tracking issue:

rust-lang#129041
mammothbane added a commit to mammothbane/rust that referenced this issue Sep 20, 2024
This change `const`-qualifies many methods on Vec and String, notably
`as_slice`, `as_str`, `len`. These changes are made behind the unstable
feature flag `const_vec_string_slice` with the following tracking issue:

rust-lang#129041
mammothbane added a commit to mammothbane/rust that referenced this issue Sep 20, 2024
This change `const`-qualifies many methods on Vec and String, notably
`as_slice`, `as_str`, `len`. These changes are made behind the unstable
feature flag `const_vec_string_slice` with the following tracking issue:

rust-lang#129041
mammothbane added a commit to mammothbane/rust that referenced this issue Oct 6, 2024
This change `const`-qualifies many methods on Vec and String, notably
`as_slice`, `as_str`, `len`. These changes are made behind the unstable
feature flag `const_vec_string_slice` with the following tracking issue:

rust-lang#129041
mammothbane added a commit to mammothbane/rust that referenced this issue Oct 6, 2024
This change `const`-qualifies many methods on Vec and String, notably
`as_slice`, `as_str`, `len`. These changes are made behind the unstable
feature flag `const_vec_string_slice` with the following tracking issue:

rust-lang#129041
mammothbane added a commit to mammothbane/rust that referenced this issue Oct 6, 2024
This change `const`-qualifies many methods on Vec and String, notably
`as_slice`, `as_str`, `len`. These changes are made behind the unstable
feature flag `const_vec_string_slice` with the following tracking issue:

rust-lang#129041
mammothbane added a commit to mammothbane/rust that referenced this issue Oct 6, 2024
This change `const`-qualifies many methods on Vec and String, notably
`as_slice`, `as_str`, `len`. These changes are made behind the unstable
feature flag `const_vec_string_slice` with the following tracking issue:

rust-lang#129041
@RalfJung RalfJung added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Nov 30, 2024
@RalfJung
Copy link
Member

@rust-lang/libs-api from a const-eval perspective, these functions all look totally harmless. One can't actually construct non-trivial Vec/String in const, but according to the examples above it could still be useful to have these as const fn. So, I propose we move ahead with stabilizing these.

@rfcbot
Copy link
Collaborator

rfcbot commented Nov 30, 2024

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.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Nov 30, 2024
@dtolnay dtolnay removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Nov 30, 2024
@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Jan 27, 2025
@rfcbot
Copy link
Collaborator

rfcbot commented Jan 27, 2025

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Feb 6, 2025
@rfcbot
Copy link
Collaborator

rfcbot commented Feb 6, 2025

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.

@rfcbot rfcbot added the to-announce Announce this issue on triage meeting label Feb 6, 2025
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Feb 7, 2025
@Kixunil
Copy link
Contributor

Kixunil commented Feb 20, 2025

The issue description is missing checkmark in FCP.

Kixunil added a commit to Kixunil/rust that referenced this issue Feb 20, 2025
This feature was approved for stabilization in
rust-lang#129041 (comment)
so this change stabilizes it.
Kixunil added a commit to Kixunil/rust that referenced this issue Feb 20, 2025
This feature was approved for stabilization in
rust-lang#129041 (comment)
so this change stabilizes it.
@tgross35
Copy link
Contributor

As @RalfJung mentioned on the PR, there are a few methods gated by this feature that were not mentioned in the tracking issue or FCP links:

impl String {
    pub const fn as_mut_str(&mut self) -> &mut str;
    pub const unsafe fn as_mut_vec(&mut self) -> &mut Vec<u8>;
}

impl Vec<T> {
    pub const fn as_mut_slice(&mut self) -> &mut [T];
    pub const fn as_mut_ptr(&mut self) -> *mut T;
}

Libs-api could you take a look at these?

@rustbot label +I-libs-api-nominated

@rustbot rustbot added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Feb 20, 2025
@Amanieu Amanieu removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Feb 25, 2025
@Amanieu
Copy link
Member

Amanieu commented Feb 25, 2025

I started a new FCP on #137319.

Kixunil added a commit to Kixunil/rust that referenced this issue Mar 8, 2025
This feature was approved for stabilization in
rust-lang#129041 (comment)
so this change stabilizes it.
Kixunil added a commit to Kixunil/rust that referenced this issue Mar 8, 2025
This feature was approved for stabilization in
rust-lang#129041 (comment)
so this change stabilizes it.
Kixunil added a commit to Kixunil/rust that referenced this issue Mar 8, 2025
This feature was approved for stabilization in
rust-lang#129041 (comment)
so this change stabilizes it.
jieyouxu added a commit to jieyouxu/rust that referenced this issue Mar 9, 2025
…-slice, r=dtolnay

Stabilize `const_vec_string_slice`

This feature was approved for stabilization in
rust-lang#129041 (comment) so this change stabilizes it.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 9, 2025
…-slice, r=dtolnay

Stabilize `const_vec_string_slice`

This feature was approved for stabilization in
rust-lang#129041 (comment) so this change stabilizes it.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 9, 2025
Rollup merge of rust-lang#137319 - Kixunil:stabilize-const-vec-string-slice, r=dtolnay

Stabilize `const_vec_string_slice`

This feature was approved for stabilization in
rust-lang#129041 (comment) so this change stabilizes it.
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this issue Mar 14, 2025
This feature was approved for stabilization in
rust-lang#129041 (comment)
so this change stabilizes it.
@cuviper cuviper added this to the 1.87.0 milestone Mar 21, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-str Area: str and String C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests