Skip to content

Commit becdca9

Browse files
Merge pull request #814 from ehuss/update-tuple-index
Update tuple index token.
2 parents a6efccd + 1a36151 commit becdca9

File tree

5 files changed

+31
-13
lines changed

5 files changed

+31
-13
lines changed

src/expressions/enum-variant-expr.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Enum variant expressions have the same syntax, behavior, and restrictions as [st
4141
expressions][structs], except they do not support base update with the `..` syntax.
4242

4343
[IDENTIFIER]: ../identifiers.md
44-
[TUPLE_INDEX]: ../tokens.md#integer-literals
44+
[TUPLE_INDEX]: ../tokens.md#tuple-index
4545
[_Expression_]: ../expressions.md
4646
[_PathInExpression_]: ../paths.md#paths-in-expressions
4747
[structs]: struct-expr.md

src/expressions/struct-expr.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ expressions].
140140

141141
[IDENTIFIER]: ../identifiers.md
142142
[Inner attributes]: ../attributes.md
143-
[TUPLE_INDEX]: ../tokens.md#integer-literals
143+
[TUPLE_INDEX]: ../tokens.md#tuple-index
144144
[_Expression_]: ../expressions.md
145145
[_InnerAttribute_]: ../attributes.md
146146
[_PathInExpression_]: ../paths.md#paths-in-expressions

src/expressions/tuple-expr.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ assert_eq!(unit_x.0, 1.0);
5555
```
5656

5757
[Inner attributes]: ../attributes.md
58-
[TUPLE_INDEX]: ../tokens.md#integer-literals
58+
[TUPLE_INDEX]: ../tokens.md#tuple-index
5959
[_Expression_]: ../expressions.md
6060
[_InnerAttribute_]: ../attributes.md
6161
[attributes on block expressions]: block-expr.md#attributes-on-block-expressions

src/patterns.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ Reference patterns are always irrefutable.
481481
>    `..`
482482
483483
[_OuterAttribute_]: attributes.md
484-
[TUPLE_INDEX]: tokens.md#integer-literals
484+
[TUPLE_INDEX]: tokens.md#tuple-index
485485

486486
Struct patterns match struct values that match all criteria defined by its subpatterns.
487487
They are also used to [destructure](#destructuring) a struct.

src/tokens.md

+27-9
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,6 @@ literal_. The grammar for recognizing the two kinds of literals is mixed.
329329
> DEC_LITERAL :\
330330
> &nbsp;&nbsp; DEC_DIGIT (DEC_DIGIT|`_`)<sup>\*</sup>
331331
>
332-
> TUPLE_INDEX :\
333-
> &nbsp;&nbsp; &nbsp;&nbsp; `0`
334-
> &nbsp;&nbsp; | NON_ZERO_DEC_DIGIT DEC_DIGIT<sup>\*</sup>
335-
>
336332
> BIN_LITERAL :\
337333
> &nbsp;&nbsp; `0b` (BIN_DIGIT|`_`)<sup>\*</sup> BIN_DIGIT (BIN_DIGIT|`_`)<sup>\*</sup>
338334
>
@@ -348,8 +344,6 @@ literal_. The grammar for recognizing the two kinds of literals is mixed.
348344
>
349345
> DEC_DIGIT : [`0`-`9`]
350346
>
351-
> NON_ZERO_DEC_DIGIT : [`1`-`9`]
352-
>
353347
> HEX_DIGIT : [`0`-`9` `a`-`f` `A`-`F`]
354348
>
355349
> INTEGER_SUFFIX :\
@@ -360,9 +354,6 @@ An _integer literal_ has one of four forms:
360354

361355
* A _decimal literal_ starts with a *decimal digit* and continues with any
362356
mixture of *decimal digits* and _underscores_.
363-
* A _tuple index_ is either `0`, or starts with a *non-zero decimal digit* and
364-
continues with zero or more decimal digits. Tuple indexes are used to refer
365-
to the fields of [tuples], [tuple structs], and [tuple variants].
366357
* A _hex literal_ starts with the character sequence `U+0030` `U+0078`
367358
(`0x`) and continues as any mixture (with at least one digit) of hex digits
368359
and underscores.
@@ -442,6 +433,33 @@ a single integer literal.
442433

443434
[unary minus operator]: expressions/operator-expr.md#negation-operators
444435

436+
#### Tuple index
437+
438+
> **<sup>Lexer</sup>**\
439+
> TUPLE_INDEX: \
440+
> &nbsp;&nbsp; INTEGER_LITERAL
441+
442+
A tuple index is used to refer to the fields of [tuples], [tuple structs], and
443+
[tuple variants].
444+
445+
Tuple indices are compared with the literal token directly. Tuple indices
446+
start with `0` and each successive index increments the value by `1` as a
447+
decimal value. Thus, only decimal values will match, and the value must not
448+
have any extra `0` prefix characters.
449+
450+
```rust,compile_fail
451+
let example = ("dog", "cat", "horse");
452+
let dog = example.0;
453+
let cat = example.1;
454+
// The following examples are invalid.
455+
let cat = example.01; // ERROR no field named `01`
456+
let horse = example.0b10; // ERROR no field named `0b10`
457+
```
458+
459+
> **Note**: The tuple index may include an `INTEGER_SUFFIX`, but this is not
460+
> intended to be valid, and may be removed in a future version. See
461+
> <https://github.com/rust-lang/rust/issues/60210> for more information.
462+
445463
#### Floating-point literals
446464

447465
> **<sup>Lexer</sup>**\

0 commit comments

Comments
 (0)