Skip to content

Commit 8c38dfd

Browse files
committed
Describe (a,) vs (a) in docs
Fixes #24730
1 parent 2f613bf commit 8c38dfd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/doc/reference.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -2431,11 +2431,18 @@ Tuples are written by enclosing zero or more comma-separated expressions in
24312431
parentheses. They are used to create [tuple-typed](#tuple-types) values.
24322432

24332433
```{.tuple}
2434-
(0,);
24352434
(0.0, 4.5);
24362435
("a", 4usize, true);
24372436
```
24382437

2438+
You can disambiguate a single-element tuple from a value in parentheses with a
2439+
comma:
2440+
2441+
```
2442+
(0,); // single-element tuple
2443+
(0); // zero in parentheses
2444+
```
2445+
24392446
### Unit expressions
24402447

24412448
The expression `()` denotes the _unit value_, the only value of the type with

src/doc/trpl/primitive-types.md

+8
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ or “breaks up” the tuple, and assigns the bits to three bindings.
248248

249249
This pattern is very powerful, and we’ll see it repeated more later.
250250

251+
You can disambiguate a single-element tuple from a value in parentheses with a
252+
comma:
253+
254+
```
255+
(0,); // single-element tuple
256+
(0); // zero in parentheses
257+
```
258+
251259
## Tuple Indexing
252260

253261
You can also access fields of a tuple with indexing syntax:

0 commit comments

Comments
 (0)