about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-10-28 16:18:16 -0700
committerBrian Anderson <banderson@mozilla.com>2011-10-28 16:18:16 -0700
commit6afecc37e33713de6b372e4bfa9c348f9de4aab6 (patch)
tree97d3d5fe3e370036bafd04334fa5d55ed4db5c96
parentba1df0eda9b0b36ef2f7b2dd69535621ca35ffb2 (diff)
downloadrust-6afecc37e33713de6b372e4bfa9c348f9de4aab6.tar.gz
rust-6afecc37e33713de6b372e4bfa9c348f9de4aab6.zip
Document the nullary-variant period in alt patterns
-rw-r--r--doc/rust.texi9
1 files changed, 9 insertions, 0 deletions
diff --git a/doc/rust.texi b/doc/rust.texi
index 82b7f1d429c..04abd97fa55 100644
--- a/doc/rust.texi
+++ b/doc/rust.texi
@@ -3396,12 +3396,21 @@ alt x @{
     cons(10, _) @{
         process_ten();
     @}
+    nil. @{
+        ret;
+    @}
     _ @{
         fail;
     @}
 @}
 @end example
 
+Note in the above example that @code{nil} is followed by a period. This is
+required syntax for pattern matching a nullary tag variant, to distingush the
+variant @code{nil} from a binding to variable @code{nil}. Without the period
+the value of @code{x} would be bound to variable @code{nil} and the compiler
+would issue an error about the final wildcard case being unreachable.
+
 Multiple alternative patterns may be joined with the @code{|} operator.  A
 range of values may be specified with @code{to}.  For example: