Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRFC for inclusive ranges with ... #1192
Conversation
This comment has been minimized.
This comment has been minimized.
|
Imo we should try providing a |
gsingh93
reviewed
Jul 7, 2015
|
|
||
| This struct implements the standard traits (`Clone`, `Debug` etc.), | ||
| but, unlike the other `Range*` types, does not implement `Iterator` | ||
| directly, since it cannot do so correctly without more internal |
This comment has been minimized.
This comment has been minimized.
gsingh93
Jul 7, 2015
Can you clarify why more state is needed? Why not just increment start while start is less than or equal to end?
This comment has been minimized.
This comment has been minimized.
Gankro
Jul 7, 2015
Contributor
@gsingh93 The problem is that 0...u8::MAX has 257 states: Some(i) for all i; and None.
So you can't modify only one bound and get all the states. You have two options:
- extra flag for "inclusive case yielded"
- do a checked_add on each step, and if it fails then decrement the maximum instead of increment the minimum (symmetric logic applies for
next_back)
This comment has been minimized.
This comment has been minimized.
oli-obk
Jul 8, 2015
Contributor
so couldn't RangeInclusive simply get another field that is set during desugaring?
This comment has been minimized.
This comment has been minimized.
huonw
Jul 8, 2015
Author
Member
I discussed it with a few people while writing the API, but got such negative feedback that I didn't even think to put it as an alternative. However, several people seem to be in support of it.
This comment has been minimized.
This comment has been minimized.
|
@Kimundi VG can still use |
alexcrichton
added
T-lang
T-libs
labels
Jul 8, 2015
This comment has been minimized.
This comment has been minimized.
|
I want inclusive ranges, and I want the syntax to be As for variadics, if the syntaxes turn out to be in conflict in some way, I'd rather have |
This comment has been minimized.
This comment has been minimized.
|
Oh, also: I think that |
This comment has been minimized.
This comment has been minimized.
|
Agreed with niko, though I'd be interested in investigating the API and performance impact of doing the hack I suggest to avoid a second field. You need to do a check in every step anyway. Might as well fold it into the add, right? Things that come to mind:
|
This comment has been minimized.
This comment has been minimized.
|
How common are inclusive ranges? I'm wary of putting a language sugar into places where a programmer benefits from it like once a year. (Library sugar like On the other side, inclusive ranges do improve consistency and completeness of the language, that already has inclusive range patterns and exclusive range expressions. On these grounds, I'd suggest to extend the RFC with half-open inclusive range |
This comment has been minimized.
This comment has been minimized.
|
@petrochenkov I agree that this works best if we have half-open inclusive ranges and exclusive range patterns as well. If we didn't already have inclusive patterns, I would prefer a method too. |
huonw
self-assigned this
Jul 8, 2015
This comment has been minimized.
This comment has been minimized.
|
CC #947 |
This comment has been minimized.
This comment has been minimized.
|
Yeah LGTM. |
huonw
added some commits
Jul 31, 2015
This comment has been minimized.
This comment has been minimized.
|
I've updated the RFC to include |
This comment has been minimized.
This comment has been minimized.
|
Hear ye, hear ye. This RFC is entering final comment period. |
nikomatsakis
added
the
final-comment-period
label
Aug 7, 2015
This comment has been minimized.
This comment has been minimized.
|
@huonw looks good to me. |
This comment has been minimized.
This comment has been minimized.
|
I realize this problem already exists with patterns, but I don't like that
Therefore I favor |
This comment has been minimized.
This comment has been minimized.
|
I think it's too similar to |
aturon
referenced this pull request
Aug 12, 2015
Closed
Tracking issue for `drain` stabilization #27711
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this at triage today, and our conclusion was that we're ok with the structures defined here. The best route forward is probably to leave the |
alexcrichton
referenced this pull request
Aug 13, 2015
Closed
Tracking issue for iter::range_inclusive #27777
This comment has been minimized.
This comment has been minimized.
bluss
commented
Aug 13, 2015
|
Will slices and vectors be indexed with inclusive ranges? |
This comment has been minimized.
This comment has been minimized.
|
@bluss not sure; definitely not initially, and seems like that would be best be considered/proposed as a separate RFC. |
This comment has been minimized.
This comment has been minimized.
bluss
commented
Aug 13, 2015
|
Slice use of inclusive ranges seems to be an aspect that needs to be covered as well. Without it, this RFC adds an inconsistency. If we don't want to allow |
This comment has been minimized.
This comment has been minimized.
|
Heh, it didn't occur to me that this RFC wouldn't include slicing of slices/vectors with inclusive ranges. I do think we should support it, I think it'll be weird to have inclusive ranges but not support them in the area that is probably most commonly used, even if it eventually comes later. It feels to me like it should be a complete package. |
This comment has been minimized.
This comment has been minimized.
placrosse
commented
Sep 2, 2015
|
@rkjnsn +1 for a...b Consistency with match patterns for both .. and ... will result in the least surprising behavior |
This comment has been minimized.
This comment has been minimized.
You are just quibbling. Yes 99999999 vs 999999999 is not a significant difference, so does |
This comment has been minimized.
This comment has been minimized.
gilescope
commented
Sep 2, 2015
|
+1 for ... as inclusive. |
This comment has been minimized.
This comment has been minimized.
main--
commented
Sep 2, 2015
|
While I agree that the current proposal may lead to confusion because of the small visual difference, I really don't think there's any way around this unless patterns are changed as well. Otherwise, the resulting syntax asymmetry is simply much worse. |
This comment has been minimized.
This comment has been minimized.
|
I think the fact that we already have |
This comment has been minimized.
This comment has been minimized.
|
My feeling is that we already had this debate back when we adopted |
nikomatsakis
referenced this pull request
Sep 4, 2015
Closed
Tracking issue for `..=` inclusive ranges (RFC #1192) -- originally `...` #28237
nikomatsakis
merged commit 17e2347
into
rust-lang:master
Sep 4, 2015
nikomatsakis
added a commit
that referenced
this pull request
Sep 4, 2015
This comment has been minimized.
This comment has been minimized.
|
Huzzah! The language design subteam has decided to accept this RFC. There were two major points of contention:
|
This comment has been minimized.
This comment has been minimized.
|
Awesome. |
This comment has been minimized.
This comment has been minimized.
|
So, after the fact (sorry if this is way to late but this hasn't been stabalized yet)... How about using an enum to represent enum RangeInclusive<T> {
Empty,
NonEmpty {
start: T,
end: T,
}
}Rational:
|
tari
added a commit
to tari/rfcs
that referenced
this pull request
Sep 8, 2015
huonw
deleted the
huonw:inclusive
branch
Dec 21, 2015
bors
added a commit
to rust-lang/rust
that referenced
this pull request
Mar 5, 2016
bors
added a commit
to rust-lang/rust
that referenced
this pull request
Mar 6, 2016
durka
referenced this pull request
Mar 11, 2016
Closed
Contradiction in RFC1192 (Inclusive Ranges) #1537
durka
referenced this pull request
Apr 25, 2017
Merged
Make RangeInclusive just a two-field struct (amend 1192) #1980
This comment has been minimized.
This comment has been minimized.
purpleposeidon
commented
Jan 21, 2018
|
I rather missed the boat on this alternative syntax suggestion: |
huonw commentedJul 7, 2015
Rendered