Skip to content

Commit 001a416

Browse files
committed
Address some comments
1 parent 2b940a2 commit 001a416

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

text/0000-subslice-pattern-syntax.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ can take it as a default.
4848
There was no visible demand for implementing half-bounded ranges in patterns so far, but if they
4949
are implemented in the future they will be able to be used in slice patterns as well, but they
5050
will require explicit grouping with recently implemented
51-
[parentheses in patterns](https://github.com/rust-lang/rust/pull/48500).
51+
[parentheses in patterns](https://github.com/rust-lang/rust/pull/48500) (`[a, (..end)]`) or an
52+
explicitly written start boundary (`[a, 0 .. end]`).
5253
We can also make *some* disambiguation effort and, for example, interpret `..LITERAL` as a
5354
range because `LITERAL` can never match a subslice. Time will show if such an effort is necessary
5455
or not.
@@ -57,6 +58,11 @@ If/when half-bounded ranges are supported in patterns, for better future compati
5758
to reserve `..PAT` as "rest of the list" in tuples and tuple structs as well, and avoid interpreting
5859
it as a range pattern in those positions.
5960

61+
Note that ambiguity with unbounded ranges as they are used in expressions (`..`) already exists in
62+
variant `Variant(..)` and tuple `(a, b, ..)` patterns, but it's very unlikely that the `..` syntax
63+
will ever be used in patterns in the range meaning because it duplicates functionality of the
64+
wildcard pattern `_`.
65+
6066
#### `..PAT` vs `PAT..`
6167

6268
Originally Rust used syntax `..PAT` for subslice patterns.
@@ -139,8 +145,9 @@ The `PAT..` alternative was discussed in the motivational part of the RFC.
139145
More complex syntaxes derived from `..` are possible, they use additional tokens to avoid the
140146
ambiguity with ranges, for example
141147
[`..PAT..`](https://github.com/rust-lang/rust/issues/23121#issuecomment-301485132), or
142-
`.. @ PAT` or `PAT @ ..` (original comments seem to be lost by GitHub), or other similar
143-
alternatives.
148+
[`.. @ PAT`](https://github.com/rust-lang/rust/issues/23121#issuecomment-280920062) or
149+
[`PAT @ ..`](https://github.com/rust-lang/rust/issues/23121#issuecomment-280906823), or other
150+
similar alternatives.
144151
We reject these syntaxes because they only bring benefits in incredibly contrived cases using a
145152
feature that doesn't even exist yet, but normally they only add symbolic noise.
146153

@@ -150,7 +157,8 @@ More radical syntax changes not keeping consistency with `..`, for example
150157
# Prior art
151158
[prior-art]: #prior-art
152159

153-
Some other languages like Scala or F# has list/array patterns, but their
160+
Some other languages like Haskell (`first_elem : rest_of_the_list`),
161+
Scala, or F# (`first_elem :: rest_of_the_list`) has list/array patterns, but their
154162
syntactic choices are quite different from Rust's general style.
155163

156164
"Rest of the list" in patterns was previously discussed in

0 commit comments

Comments
 (0)