Skip to content
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 slice::split_at_unchecked() and split_at_mut_unchecked() #76014

Closed
2 of 3 tasks
sdroege opened this issue Aug 28, 2020 · 14 comments · Fixed by #120577
Closed
2 of 3 tasks

Tracking Issue for slice::split_at_unchecked() and split_at_mut_unchecked() #76014

sdroege opened this issue Aug 28, 2020 · 14 comments · Fixed by #120577
Labels
A-slice Area: [T] B-unstable Feature: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. 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. Libs-Tracked Libs issues that are tracked on the team's project board. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@sdroege
Copy link
Contributor

sdroege commented Aug 28, 2020

This is a tracking issue for the slice::split_at_unchecked() and slice::split_at_mut_unchecked() functions.
The feature gate for the issue is #![feature(slice_split_at_unchecked)].

API

impl<T> [T] {
    pub const unsafe fn split_at_unchecked(&self, mid: usize) -> (&[T], &[T]);
    pub const unsafe fn split_at_mut_unchecked(&mut self, mid: usize) -> (&mut [T], &mut [T]);
}

Steps

Unresolved Questions

  • Is this worth having if it's simple enough to implement manually around slice::get_unchecked() or slice::from_raw_parts()?
@sdroege sdroege added the C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. label Aug 28, 2020
@jonas-schievink jonas-schievink added B-unstable Feature: Implemented in the nightly compiler and unstable. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Aug 28, 2020
sdroege added a commit to sdroege/rust that referenced this issue Aug 30, 2020
…ed()

These are unsafe variants of the non-unchecked functions and don't do
any bounds checking.

For the time being these are not public and only a preparation for the
following commit. Making it public and stabilization can follow later
and be discussed in rust-lang#76014 .
@sdroege
Copy link
Contributor Author

sdroege commented Aug 31, 2020

This is now merged but not as public API.

I think this would be useful to have though, at least the mutable version as it's dealing with raw pointers and it's much harder to use split_at_mut_unchecked() wrong than to do a mistake when reimplementing it. I also checked some of my code and there are various places where this would be useful to use (and I have a couple of ad-hoc implementations of this).

There are probably also some places in std.

@KodrAus KodrAus added the Libs-Tracked Libs issues that are tracked on the team's project board. label Sep 10, 2020
@KodrAus KodrAus added the A-slice Area: [T] label Sep 22, 2020
@WaffleLapkin
Copy link
Member

Why the API is private? If there is no reason, I could make a PR making it public.

I've just found myself coping the methods from std, to use them...

@thomcc
Copy link
Member

thomcc commented Aug 5, 2021

It's very strange that this API is both private and unstable with a tracking issue. Was this intentional?

bors added a commit to rust-lang-ci/rust that referenced this issue Oct 3, 2021
…r=dtolnay

Make `<[T]>::split_at_unchecked` and `<[T]>::split_at_mut_unchecked` public

The methods were originally added in rust-lang#75936 (sdroege@30dc32b), but for some reason as private. Nevertheless, the methods have documentation and even a [tracking issue](rust-lang#76014).

It's very weird to have a tracking issue for private methods and these methods may be useful outside of the standard library. As such, this PR makes the methods public.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 22, 2021
Implement split_array and split_array_mut

This implements `[T]::split_array::<const N>() -> (&[T; N], &[T])` and `[T; N]::split_array::<const M>() -> (&[T; M], &[T])` and their mutable equivalents. These are another few “missing” array implementations now that const generics are a thing, similar to rust-lang#74373, rust-lang#75026, etc. Fixes rust-lang#74674.

This implements `[T; N]::split_array` returning an array and a slice. Ultimately, this is probably not what we want, we would want the second return value to be an array of length N-M, which will likely be possible with future const generics enhancements. We need to implement the array method now though, to immediately shadow the slice method. This way, when the slice methods get stabilized, calling them on an array will not be automatic through coercion, so we won't have trouble stabilizing the array methods later (cf. into_iter debacle).

An unchecked version of `[T]::split_array` could also be added as in rust-lang#76014. This would not be needed for `[T; N]::split_array` as that can be compile-time checked. Edit: actually, since split_at_unchecked is internal-only it could be changed to be split_array-only.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 22, 2021
Implement split_array and split_array_mut

This implements `[T]::split_array::<const N>() -> (&[T; N], &[T])` and `[T; N]::split_array::<const M>() -> (&[T; M], &[T])` and their mutable equivalents. These are another few “missing” array implementations now that const generics are a thing, similar to rust-lang#74373, rust-lang#75026, etc. Fixes rust-lang#74674.

This implements `[T; N]::split_array` returning an array and a slice. Ultimately, this is probably not what we want, we would want the second return value to be an array of length N-M, which will likely be possible with future const generics enhancements. We need to implement the array method now though, to immediately shadow the slice method. This way, when the slice methods get stabilized, calling them on an array will not be automatic through coercion, so we won't have trouble stabilizing the array methods later (cf. into_iter debacle).

An unchecked version of `[T]::split_array` could also be added as in rust-lang#76014. This would not be needed for `[T; N]::split_array` as that can be compile-time checked. Edit: actually, since split_at_unchecked is internal-only it could be changed to be split_array-only.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 23, 2021
Implement split_array and split_array_mut

This implements `[T]::split_array::<const N>() -> (&[T; N], &[T])` and `[T; N]::split_array::<const M>() -> (&[T; M], &[T])` and their mutable equivalents. These are another few “missing” array implementations now that const generics are a thing, similar to rust-lang#74373, rust-lang#75026, etc. Fixes rust-lang#74674.

This implements `[T; N]::split_array` returning an array and a slice. Ultimately, this is probably not what we want, we would want the second return value to be an array of length N-M, which will likely be possible with future const generics enhancements. We need to implement the array method now though, to immediately shadow the slice method. This way, when the slice methods get stabilized, calling them on an array will not be automatic through coercion, so we won't have trouble stabilizing the array methods later (cf. into_iter debacle).

An unchecked version of `[T]::split_array` could also be added as in rust-lang#76014. This would not be needed for `[T; N]::split_array` as that can be compile-time checked. Edit: actually, since split_at_unchecked is internal-only it could be changed to be split_array-only.
@tspiteri
Copy link
Contributor

The split_at_unchecked method was made unstably const in #100076, such that stabilizing slice_split_at_unchecked will now also make it stably const.

@sffc
Copy link

sffc commented Oct 5, 2022

Also useful would be a split_at method that returns an Option<(&[T], &[T])> instead of panicking.

@ghost
Copy link

ghost commented Apr 16, 2023

What is left to do to get this stabilized? #75936 was merged just a few days after this issue was created, so just the stabilization PR and docs, or are those done/in-progress? It seems like a pretty straightforward thing to get done, is there anything I can do to help push it along?

@InsertCreativityHere
Copy link

I'd also be willing to contribute if that'd help get this stabilized sooner!

@tgross35
Copy link
Contributor

If anyone is interested in moving this feature forward (@InsertCreativityHere?), I would suggest submitting a stabilization PR to at least get the ball rolling on discussion. Stabilization just means changing the attributes and writing a good PR message so it's quite easy (see the reference here https://rustc-dev-guide.rust-lang.org/stability.html#stabilizing-a-library-feature).

Also useful would be a split_at method that returns an Option<(&[T], &[T])> instead of panicking.

@sffc for future reference, if you have a proposal then you should submit an ACP (that's just an issue template at this repo: https://github.com/rust-lang/libs-team). Somebody actually did that recently at rust-lang/libs-team#308, and the tracking issue is here #119128

@m-ou-se m-ou-se added the I-libs-api-nominated The issue / PR has been nominated for discussion during a libs-api team meeting. label Feb 15, 2024
@m-ou-se
Copy link
Member

m-ou-se commented Feb 20, 2024

@rfcbot merge

@rfcbot
Copy link

rfcbot commented Feb 20, 2024

Team member @m-ou-se 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 Feb 20, 2024
@Amanieu Amanieu removed the I-libs-api-nominated The issue / PR has been nominated for discussion during a libs-api team meeting. label Feb 20, 2024
@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Feb 20, 2024
@rfcbot rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Feb 20, 2024
@rfcbot
Copy link

rfcbot commented Feb 20, 2024

🔔 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. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Mar 1, 2024
@rfcbot
Copy link

rfcbot commented Mar 1, 2024

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.

@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Mar 7, 2024
@bors bors closed this as completed in 71ce3c2 Mar 23, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 23, 2024
Rollup merge of rust-lang#120577 - wutchzone:slice_split_at_unchecked, r=m-ou-se

Stabilize slice_split_at_unchecked

Greetings!

I took the opportunity, and I tried to stabilize the `slice_split_at_unchecked` feature. I followed the guidelines, and I hope everything was done correctly 🤞 .

Closes rust-lang#76014
RenjiSann pushed a commit to RenjiSann/rust that referenced this issue Mar 25, 2024
…, r=m-ou-se

Stabilize slice_split_at_unchecked

Greetings!

I took the opportunity, and I tried to stabilize the `slice_split_at_unchecked` feature. I followed the guidelines, and I hope everything was done correctly 🤞 .

Closes rust-lang#76014
@Ygg01
Copy link

Ygg01 commented Apr 13, 2024

Is anything holding stabilization of this?

@WaffleLapkin
Copy link
Member

@Ygg01 you may notice that this issue is closed, this is because this feature was already stabilized in #120577. You can use it in nightly without a feature gate, or wait till stable rust version 1.79.0 which will be released on June 13 (ref).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-slice Area: [T] B-unstable Feature: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. 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. Libs-Tracked Libs issues that are tracked on the team's project board. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.