Skip to content

Commit 17e2347

Browse files
committed
Propose ...b too.
1 parent 937d9ad commit 17e2347

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

text/0000-inclusive-ranges.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@ pub struct RangeInclusive<T> {
3131
pub end: T,
3232
pub finished: bool,
3333
}
34+
35+
pub struct RangeToInclusive<T> {
36+
pub end: T,
37+
}
3438
```
3539

3640
Writing `a...b` in an expression desugars to `std::ops::RangeInclusive
37-
{ start: a, end: b, finished: false }`.
41+
{ start: a, end: b, finished: false }`. Writing `...b` in an
42+
expression desugars to `std::ops::RangeToInclusive { end: b }`.
3843

39-
This struct implements the standard traits (`Clone`, `Debug` etc.),
40-
and implements `Iterator`. The `finished` field is to allow the
44+
`RangeInclusive` implements the standard traits (`Clone`, `Debug`
45+
etc.), and implements `Iterator`. The `finished` field is to allow the
4146
`Iterator` implementation to work without hacks (see Alternatives).
4247

4348
The use of `...` in a pattern remains as testing for inclusion
@@ -59,7 +64,9 @@ semantically.)
5964
The `...` vs. `..` distinction is the exact inversion of Ruby's syntax.
6065

6166
Having an extra field in a language-level desugaring, catering to one
62-
library use-case is a little non-"hygienic".
67+
library use-case is a little non-"hygienic". It is especially strange
68+
that the field isn't consistent across the different `...`
69+
desugarings.
6370

6471
# Alternatives
6572

0 commit comments

Comments
 (0)