@@ -48,7 +48,8 @@ can take it as a default.
48
48
There was no visible demand for implementing half-bounded ranges in patterns so far, but if they
49
49
are implemented in the future they will be able to be used in slice patterns as well, but they
50
50
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] ` ).
52
53
We can also make * some* disambiguation effort and, for example, interpret ` ..LITERAL ` as a
53
54
range because ` LITERAL ` can never match a subslice. Time will show if such an effort is necessary
54
55
or not.
@@ -57,6 +58,11 @@ If/when half-bounded ranges are supported in patterns, for better future compati
57
58
to reserve ` ..PAT ` as "rest of the list" in tuples and tuple structs as well, and avoid interpreting
58
59
it as a range pattern in those positions.
59
60
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
+
60
66
#### ` ..PAT ` vs ` PAT.. `
61
67
62
68
Originally Rust used syntax ` ..PAT ` for subslice patterns.
@@ -139,8 +145,9 @@ The `PAT..` alternative was discussed in the motivational part of the RFC.
139
145
More complex syntaxes derived from ` .. ` are possible, they use additional tokens to avoid the
140
146
ambiguity with ranges, for example
141
147
[ ` ..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.
144
151
We reject these syntaxes because they only bring benefits in incredibly contrived cases using a
145
152
feature that doesn't even exist yet, but normally they only add symbolic noise.
146
153
@@ -150,7 +157,8 @@ More radical syntax changes not keeping consistency with `..`, for example
150
157
# Prior art
151
158
[ prior-art ] : #prior-art
152
159
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
154
162
syntactic choices are quite different from Rust's general style.
155
163
156
164
"Rest of the list" in patterns was previously discussed in
0 commit comments