Skip to content

Commit fe215c0

Browse files
committed
Address more comments
1 parent 3be24a6 commit fe215c0

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

text/0000-subslice-pattern-syntax.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
# Summary
77
[summary]: #summary
88

9-
Permit matching sub-slices and sub-arrays with the syntax `..`.
9+
Permit matching sub-slices and sub-arrays with the syntax `..`.
1010
Binding a variable to the expression matched by a subslice pattern can be done
11-
using the existing `<IDENT> @ <PAT>` syntax, for example:
11+
using syntax `<IDENT> @ ..` similar to the existing `<IDENT> @ <PAT>` syntax, for example:
1212

1313
```rust
1414
// Binding a sub-array:
@@ -75,17 +75,20 @@ match v {
7575
# Reference-level explanation
7676
[reference-level-explanation]: #reference-level-explanation
7777

78-
`..` can be used as a pattern for matching sub-slices and sub-arrays.
78+
`..` can be used as a pattern fragment for matching sub-slices and sub-arrays.
7979
It is treated as a "non-reference-pattern" for the purpose of determining default-binding-modes,
8080
and so shifts the binding mode to by-`ref` or by-`ref mut` when used to match a subsection of a
8181
reference or mutable reference to a slice or array.
8282

83-
`@` can be used to bind the result of a `..` pattern to an identifier.
83+
`@` can be used to bind the result of `..` to an identifier.
8484

8585
When used to match against a non-reference slice (`[u8]`), `x @ ..` would attempt to bind
8686
by-value, which would fail in the case that users haven't enabled `feature(unsized_locals)`
8787
(since otherwise it's not possible to bind `[u8]` to a variable directly).
8888

89+
`..`/`IDENT @ ..` is not a full pattern syntax, but rather a part of slice, tuple and tuple
90+
struct pattern syntaxes. In particular, `..` is not accepted by the `pat` macro matcher.
91+
8992
# Drawbacks
9093
[drawbacks]: #drawbacks
9194

@@ -94,8 +97,6 @@ None known.
9497
# Rationale and alternatives
9598
[alternatives]: #alternatives
9699

97-
The `PAT..` alternative was discussed in the motivational part of the RFC.
98-
99100
More complex syntaxes derived from `..` are possible, they use additional tokens to avoid the
100101
ambiguity with ranges, for example
101102
[`..PAT..`](https://github.com/rust-lang/rust/issues/23121#issuecomment-301485132), or
@@ -198,3 +199,9 @@ syntactic choices are quite different from Rust's general style.
198199
[unresolved]: #unresolved-questions
199200

200201
None known.
202+
203+
# Future possibilities
204+
[future-possibilities]: #future-possibilities
205+
206+
Turn `..` into a full pattern syntactically accepted in any pattern position,
207+
(including `pat` matchers in macros), but rejected semantically outside of slice and tuple patterns.

0 commit comments

Comments
 (0)