Skip to content

Commit 6afecc3

Browse files
committed
Document the nullary-variant period in alt patterns
1 parent ba1df0e commit 6afecc3

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

doc/rust.texi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3396,12 +3396,21 @@ alt x @{
33963396
cons(10, _) @{
33973397
process_ten();
33983398
@}
3399+
nil. @{
3400+
ret;
3401+
@}
33993402
_ @{
34003403
fail;
34013404
@}
34023405
@}
34033406
@end example
34043407

3408+
Note in the above example that @code{nil} is followed by a period. This is
3409+
required syntax for pattern matching a nullary tag variant, to distingush the
3410+
variant @code{nil} from a binding to variable @code{nil}. Without the period
3411+
the value of @code{x} would be bound to variable @code{nil} and the compiler
3412+
would issue an error about the final wildcard case being unreachable.
3413+
34053414
Multiple alternative patterns may be joined with the @code{|} operator. A
34063415
range of values may be specified with @code{to}. For example:
34073416

0 commit comments

Comments
 (0)