-
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 RangeBounds #30877
Comments
I'm currently working on inclusive ranges, which is why I noticed this. A PR to change the issue link is incoming. |
…sue, r=nagisa see rust-lang#27711 and rust-lang#30877 r? @alexcrichton
This PR implements [RFC 1192](https://github.com/rust-lang/rfcs/blob/master/text/1192-inclusive-ranges.md), which is triple-dot syntax for inclusive range expressions. The new stuff is behind two feature gates (one for the syntax and one for the std::ops types). This replaces the deprecated functionality in std::iter. Along the way I simplified the desugaring for all ranges. This is my first contribution to rust which changes more than one character outside of a test or comment, so please review carefully! Some of the individual commit messages have more of my notes. Also thanks for putting up with my dumb questions in #rust-internals. - For implementing `std::ops::RangeInclusive`, I took @Stebalien's suggestion from rust-lang/rfcs#1192 (comment). It seemed to me to make the implementation easier and increase type safety. If that stands, the RFC should be amended to avoid confusion. - I also kind of like @glaebhoerl's [idea](rust-lang/rfcs#1254 (comment)), which is unified inclusive/exclusive range syntax something like `x>..=y`. We can experiment with this while everything is behind a feature gate. - There are a couple of FIXMEs left (see the last commit). I didn't know what to do about `RangeArgument` and I haven't added `Index` impls yet. Those should be discussed/finished before merging. cc @gankro since you [complained](https://www.reddit.com/r/rust/comments/3xkfro/what_happened_to_inclusive_ranges/cy5j0yq) cc #27777 #30877 #1192 rust-lang/rfcs#1254 relevant to #28237 (tracking issue)
This trait is not actually being exported by |
The libs team discussed this, and are placing pub enum Bound<T> {
Unbound,
Inclusive(T),
Exclusive(T),
}
pub trait RangeArgument<T> {
fn lower(&self) -> Bound<&T>;
fn upper(&self) -> Bound<&T>;
} |
@sfackler shouldn't the new API go though another stabilization period? Also, a way to extract the bounds by-value would be nice (but probably not necessary). |
Probably at this point yeah, particularly since we still haven't actually made the change. |
The libs team discussed this at triage the other day and the conclusion was to punt on stabilization/deprecation because we didn't have time to implement the changes here |
Question: is there a reason why this trait is in |
I don't think there's a good reason for it to not be in core off the top of my head - it should probably move! |
Should also impl RangeArgument for usize. impl RangeArgument<usize> for usize {
fn start(&self) -> Bound<usize> { Included(self) }
fn end(&self) -> Bound<usize> { Included(self) }
} |
@J-F-Liu There’s also a |
@SimonSapin thanks for let me know this, it indicates should impl RangeArgument for usize as well. |
Would people be willing to accept a PR for moving this to core? Everything would have the same features, and Only problem I see is that |
Makes sense to move to me!
…On Sat, Apr 8, 2017 at 9:35 PM Clar ***@***.***> wrote:
Would people be willing to accept a PR for moving this to core? Everything
would have the same features, and collections would re-export them for
compatibility.
Only problem I see is that Bound is already stabilised but I'm not too
worried about that.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#30877 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABY2UaqUry1YVcrwUqcWz7caLespreVdks5ruGAdgaJpZM4HEQZG>
.
|
Can I nominate this for FCP? Seems like it does what it needs to do; fully general. |
I've had various ideas w.r.t. the design which I posted and each time the discussion got moved somewhere else, I can't remember what they were and I'm too lazy to look them up, but at least let's call it something like |
Seems reasonable to FCP for stabilization. I'd be fine renaming as part of that! @rfcbot fcp merge |
On stable Rust today, you can also write your own |
Yes, good point -- I hadn't considered that. I'm going to do it even though it feels pretty icky. Despite my griping, thanks for the pointer! |
In case anyone else has a collection they want RangeArgument for: https://github.com/Gankro/thin-vec/blob/master/src/range.rs This is an especially clean case of the unstable trait in public API pattern, as there's very little incentive to implement these traits outside of the like 4-5 std types which do. |
PR #49163: Rename RangeArgument to RangeBounds, move it and Bound to libcore |
Assuming this PR is accepted, the only issue in this thread that I feel might not be resolved is the possibility of replacing this trait with a type to be used with @sfackler wrote “the @rust-lang/libs what do you think? If we decide to keep the dedicated trait, should we do another round of FCP or are we good to stabilize? (Again assuming the PR linked above.) |
Rename RangeArgument to RangeBounds, move it and Bound to libcore As proposed in the tracking issue: #30877 Changes to *stable* items: * `core::ops::Bound` / `std::ops::Bound` is new * `std::collections::Bound` is a deprecated reexport of it (does this actually cause a warning?) Changes to *unstable* items * `alloc::Bound` is gone * `alloc::range::RangeArgument` is moved to `core::ops::RangeBounds` / `std::ops::RangeBounds` * `alloc::range` is gone * `std::collections::range::RangeArgument` is deprecated reexport, to be removed later * `std::collections::range` is deprecated, to be removed later * `impl RangeBounds<T> for Range{,From,To,Inclusive,ToInclusive}<&T>` are added The idea of replacing this trait with a type to be used with `Into<_>` is left for future consideration / work. (Fixes rust-lang/rust-clippy#2552.)
The libs team discussed this and consensus was to stabilize after renaming the methods to @rfcbot fcp merge Affected APIs are: pub trait RangeBounds<T: ?Sized> {
fn start_bound(&self) -> Bound<&T>;
fn end_bound(&self) -> Bound<&T>;
}
impl<T: ?Sized> RangeBounds<T> for RangeFull {…}
impl<T> RangeBounds<T> for RangeFrom<T> {…}
impl<T> RangeBounds<T> for RangeTo<T> {…}
impl<T> RangeBounds<T> for Range<T> {…}
impl<T> RangeBounds<T> for RangeInclusive<T> {…}
impl<T> RangeBounds<T> for RangeToInclusive<T> {…}
impl<T> RangeBounds<T> for (Bound<T>, Bound<T>) {…}
impl<'a, T: ?Sized + 'a> RangeBounds<T> for (Bound<&'a T>, Bound<&'a T>) {…}
impl<'a, T> RangeBounds<T> for RangeFrom<&'a T> {…}
impl<'a, T> RangeBounds<T> for RangeTo<&'a T> {…}
impl<'a, T> RangeBounds<T> for Range<&'a T> {…}
impl<'a, T> RangeBounds<T> for RangeInclusive<&'a T> {…}
impl<'a, T> RangeBounds<T> for RangeToInclusive<&'a T> {…} |
Team member @SimonSapin has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), 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. |
Since the bikeshed was opened: why not |
This change is motivated by avoiding collision with the exact |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period is now complete. |
rename RangeBounds::start() -> start_bound() rename RangeBounds::end() -> end_bound()
was already moved to ops::RangeBounds (see rust-lang#30877)
The collections_range FPC closed, with the decision to rename to RangeBounds::start_bound(). rust-lang/rust#30877
stabilize RangeBounds collections_range #30877 The FCP for #30877 closed last month, with the decision to: 1. move from `collections::range::RangeArgument` to `ops::RangeBounds`, and 2. rename `start()` and `end()` to `start_bounds()` and `end_bounds()`. Simon Sapin already moved it to `ops::RangeBounds` in #49163. I renamed the functions, and removed the old `collections::range::RangeArgument` alias. This is my first Rust PR, please let me know if I can improve anything. This passes all tests for me, except the `clippy` tool (which uses `RangeArgument::start()`). I considered deprecating `start()` and `end()` instead of removing them, but the contribution guidelines indicate we can break `clippy` temporarily. I thought it was best to remove the functions, since we're worried about name collisions with `Range::start` and `end`. Closes #30877.
I think a method like This would give a way to get the inner values without having to use |
This issue tracks the
collections_range
feature which applies tostd::collections::range::RangeArgument
. It used to be lumped in withdrain
(#27711) but that was stabilized whileRangeArgument
may continue to be affected by experiments with inclusive ranges, so here we are.The text was updated successfully, but these errors were encountered: