about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-10-19 00:47:18 +0000
committerbors <bors@rust-lang.org>2014-10-19 00:47:18 +0000
commitc46812f6593eb8d9b294d082a487270d7c7be6ef (patch)
treee181dd5c772eb30de5a6bb651f8518af3a53facd
parentd8cf0239713aa5683dc80872c4ea1962599e75e7 (diff)
parentce83a24b5f525cba5bd9b734be969f4595b7ca0b (diff)
downloadrust-c46812f6593eb8d9b294d082a487270d7c7be6ef.tar.gz
rust-c46812f6593eb8d9b294d082a487270d7c7be6ef.zip
auto merge of #18120 : jrincayc/rust/match_exp, r=thestinger
Use a match expression directly in the println statement, instead of creating a second variable.  It seems weird that the current guide.md complains about creating an extra variable, when the same feature could be demonstrated without creating the extra variable.
-rw-r--r--src/doc/guide.md14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/doc/guide.md b/src/doc/guide.md
index db97fc06444..a3c508ceb24 100644
--- a/src/doc/guide.md
+++ b/src/doc/guide.md
@@ -1255,8 +1255,9 @@ version, if we had forgotten the `Greater` case, for example, our program would
 have happily compiled. If we forget in the `match`, it will not. Rust helps us
 make sure to cover all of our bases.
 
-`match` is also an expression, which means we can use it on the right hand side
-of a `let` binding. We could also implement the previous line like this:
+`match` is also an expression, which means we can use it on the right
+hand side of a `let` binding or directly where an expression is
+used. We could also implement the previous line like this:
 
 ```{rust}
 fn cmp(a: int, b: int) -> Ordering {
@@ -1269,18 +1270,15 @@ fn main() {
     let x = 5i;
     let y = 10i;
 
-    let result = match cmp(x, y) {
+    println!("{}", match cmp(x, y) {
         Less    => "less",
         Greater => "greater",
         Equal   => "equal",
-    };
-
-    println!("{}", result);
+    });
 }
 ```
 
-In this case, it doesn't make a lot of sense, as we are just making a temporary
-string where we don't need to, but sometimes, it's a nice pattern.
+Sometimes, it's a nice pattern.
 
 # Looping