Skip to content

Commit b50bcc8

Browse files
committed
Document expression order for tuple expressions.
Also removes a "you", alphabetizes the link refs, links to the disambiguated parenthetical expression, and moves a link to a link ref. I probably should have made multiple commits. Sorry.
1 parent 56a13c0 commit b50bcc8

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/expressions/tuple-expr.md

+20-6
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,29 @@
1010
> &nbsp;&nbsp; ( [_Expression_] `,` )<sup>+</sup> [_Expression_]<sup>?</sup>
1111
1212
Tuples are written by enclosing zero or more comma-separated expressions in
13-
parentheses. They are used to create [tuple-typed](../types/tuple.md)
14-
values.
13+
parentheses. They are used to create [tuple-typed] values.
1514

1615
```rust
1716
(0.0, 4.5);
1817
("a", 4usize, true);
1918
();
2019
```
2120

22-
You can disambiguate a single-element tuple from a value in parentheses with a
23-
comma:
21+
The inner expressions are evaluated from left to right.
22+
23+
```rust
24+
#// Using vec instead of array to avoid references
25+
#// since there is no stable owned array iterator
26+
#// at the time this example was written.
27+
let mut one_two = vec![1, 2].into_iter();
28+
assert_eq!(
29+
(1, 2),
30+
(one_two.next().unwrap(), one_two.next().unwrap())
31+
);
32+
```
33+
34+
Single-element tuples are disambiguated from a [parenthetical expression] with a
35+
comma before the closing parethesis:
2436

2537
```rust
2638
(0,); // single-element tuple
@@ -54,8 +66,10 @@ let unit_x = Point(1.0, 0.0);
5466
assert_eq!(unit_x.0, 1.0);
5567
```
5668

57-
[Inner attributes]: ../attributes.md
58-
[TUPLE_INDEX]: ../tokens.md#tuple-index
5969
[_Expression_]: ../expressions.md
6070
[_InnerAttribute_]: ../attributes.md
6171
[attributes on block expressions]: block-expr.md#attributes-on-block-expressions
72+
[Inner attributes]: ../attributes.md
73+
[parenthetical expression]: grouped-expr.md
74+
[tuple-typed]: ../types/tuple.md
75+
[TUPLE_INDEX]: ../tokens.md#tuple-index

0 commit comments

Comments
 (0)