-
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
Tracking Issue for slice_range #76393
Comments
…check-range, r=jyn514 Adjust documentation for slice_check_range Adjust documentation for rust-lang#76393.
With #75207 the type of this function changed, so the issue description should likely be adjusted -- unless you want to provide the old one as a convenience wrapper? I think that would be a bad idea though. The function's docs clearly position it as something used in unsafe code, and in unsafe code I'd rather not make people create slices when all they need is to compute their length. As #76662 showed, often creating those slices is not correct. |
Alternatively, maybe it would make more sense to make this a method on |
Well, the reason I chose to define it on a slice is that (I think) it's not possible to create a slice of length Outside the standard library, wouldn't |
It is possible though:
This applies inside and outside the standard library. The alternative is a raw slice, |
Right, that's what I was missing.
I agree the API change makes sense now. Thanks for the explanations! I also fixed the code sample in this issue. |
Now that it doesn't need a slice, I think this might be better. I'll think about it and likely create a PR to move it. |
Is this possible? I don't think provided methods can restrict the trait's type parameter at all, but |
Hm, you could play with something like |
Thanks. I'm not sure how I missed bounds on the method itself. |
I think having the #76885 version of this for precondition checking is great. I'm dropping by from #77480 (comment) to ponder whether there's other, more user-focused versions of this that could make sense too. Spitballing: something on |
The problem with adding it to |
Note: I didn't even realise this method existed despite searching for it, and ended up adding an implementation of |
I thought about that. Also, this is the PR for anyone reading this issue: #81108 I think it depends on how you expect your impl to be used. Would it be used in a way this method would already cover? The advantage of this method is that it can be used when you don't have a slice:
However, the design has changed a few times, so it's worth discussing what would be best. |
IMO The |
Idea: it could take That would allow a call like |
Naming this method has always been a problem. That was simply the best name I found at the time, and I'd be in favor of changing it.
This is a great idea. To avoid confusion with other |
I created the PR: #81154 |
Thanks @bluss. |
… r=KodrAus Improve design of `assert_len` It was discussed in the [tracking issue](rust-lang#76393 (comment)) that `assert_len`'s name and usage are confusing. This PR improves them based on a suggestion by `@scottmcm` in that issue. I also improved the documentation to make it clearer when you might want to use this method. Old example: ```rust let range = range.assert_len(slice.len()); ``` New example: ```rust let range = range.ensure_subset_of(..slice.len()); ``` Fixes rust-lang#81157
… r=KodrAus Improve design of `assert_len` It was discussed in the [tracking issue](rust-lang#76393 (comment)) that `assert_len`'s name and usage are confusing. This PR improves them based on a suggestion by `@scottmcm` in that issue. I also improved the documentation to make it clearer when you might want to use this method. Old example: ```rust let range = range.assert_len(slice.len()); ``` New example: ```rust let range = range.ensure_subset_of(..slice.len()); ``` Fixes rust-lang#81157
… r=KodrAus Improve design of `assert_len` It was discussed in the [tracking issue](rust-lang#76393 (comment)) that `assert_len`'s name and usage are confusing. This PR improves them based on a suggestion by ``@scottmcm`` in that issue. I also improved the documentation to make it clearer when you might want to use this method. Old example: ```rust let range = range.assert_len(slice.len()); ``` New example: ```rust let range = range.ensure_subset_of(..slice.len()); ``` Fixes rust-lang#81157
Could |
@jendrikw Unfortunately, I doubt it. This function is used primarily to apply a length to a range, but the length for |
@dylni, given the implementation of |
@reitermarkus Personally, I no longer have a use for this method, so I cannot comment on if the current implementation is useful and makes sense. Do you have examples of this method providing benefit outside of libstd? |
I used it in Stabilising would reduce the amount of code that needs to be duplicated, as is currently the case. |
I've also had a use for it recently in an API that I would like to be able to take an argument of type |
Since so many people mentioned it, I opened #121148 to add |
@reitermarkus Would you be able to create the stabilization report? Unfortunately, as I no longer make use of the feature and am not familiar with the stabilization process, I may not have the time to devote for a while. If not, I will look to create one once as soon as I have the opportunity. |
we just added a new function which isn't merged yet and is tied to the same tracking issue, so we need to spend some time for it to »bake« if we plan on stabilising this all together. We could move it to a different feature gate, but for a small feature like this, I'm not sure that's a good idea. it's fine if you can't write the stabilisation report. The person who opens the tracking issue isn't obliged to write the stabilisation report, so once we give enough time for this, I will try and look towards writing the stabilisation report for it |
#95274 added Of course for |
Add slice::try_range This adds a fallible version of the unstable `slice::range` (tracking: rust-lang#76393) which is highly requested in the tracking issue. Hoping this can slide by without an ACP (since the feature is already being tracked), but let me know otherwise.
@dtolnay To me, the point of Though of course it would be nice if the |
Good call. Now I searched GitHub for "start <= end &&" and there are a few hits that might be able to correctly use
but arguably those are APIs that would be better redesigned to use If someone wants to extend the documentation of |
Add slice::try_range This adds a fallible version of the unstable `slice::range` (tracking: rust-lang#76393) which is highly requested in the tracking issue. Hoping this can slide by without an ACP (since the feature is already being tracked), but let me know otherwise.
Rollup merge of rust-lang#121148 - clarfonthey:try-range, r=dtolnay Add slice::try_range This adds a fallible version of the unstable `slice::range` (tracking: rust-lang#76393) which is highly requested in the tracking issue. Hoping this can slide by without an ACP (since the feature is already being tracked), but let me know otherwise.
The feature gate for the issue is
#![feature(slice_range)]
.This issue currently tracks the following API:
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Steps
slice::check_range
#75207)Unresolved Questions
Should this method be defined on(MoveRangeBounds
orRange
instead?slice::check_range
toRangeBounds
#76885)Should a non-panicking version be added?#[final]
methods in traits?RangeBounds
is that todayunsafe
code can't trust any method on a not-unsafe trait to validate anything. But if this was a final method, and thus not overridable, thenunsafe
code could trust it.Implementation history
slice::check_range
#75207slice::check_range
toRangeBounds
#76885slice::range
in Improve design ofassert_len
#81154The text was updated successfully, but these errors were encountered: